Coder Social home page Coder Social logo

cdoru / aspnet-core-react-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bradymholt/aspnet-core-react-template

0.0 2.0 0.0 272 KB

ASP.NET Core 2.0 / React SPA Template App

Home Page: https://www.geekytidbits.com/asp-dotnet-core-react-template-update/

License: MIT License

C# 56.14% HTML 3.95% JavaScript 3.86% TypeScript 32.40% CSS 0.95% Python 1.80% Shell 0.91%

aspnet-core-react-template's Introduction

ASP.NET Core / React SPA Template App

This app is a template application using ASP.NET Core 2.0 for a REST/JSON API server and React for a web client.

screen recording 2017-06-10 at 04 12 pm

Overview of Stack

  • Server
    • ASP.NET Core 2.0
    • PostgresSQL
    • Entity Framework Core w/ EF Migrations
    • JSON Web Token (JWT) authorization
    • Docker used for development PostgresSQL database and MailCatcher server
  • Client
    • React
    • Webpack for asset bundling and HMR (Hot Module Replacement)
    • CSS Modules
    • Fetch API for REST requests
  • Testing
    • xUnit for .NET Core
    • Enzyme for React
    • MailCatcher for development email delivery
  • DevOps
    • Ansible playbook for provisioning (Nginx reverse proxy, SSL via Let's Encrypt, PostgresSQL backups to S3)
    • Ansible playbook for deployment

Demo

Demo Video

Setup

  1. Install the following:
  2. Run npm install && npm start
  3. Open browser and navigate to http://localhost:5000.

This template was developed and tested on macOS Sierra but should run on Windows as well. If you experience any issues getting it to run on Windows and work through them, please submit a PR!

Scripts

npm install

When first cloning the repo or adding new dependencies, run this command. This will:

  • Install Node dependencies from package.json
  • Install .NET Core dependencies from api/api.csproj and api.test/api.test.csproj (using dotnet restore)

npm start

To start the app for development, run this command. This will:

  • Run docker-compose up to ensure the PostgreSQL and MailCatcher Docker images are up and running
  • Run dotnet watch run which will build the app (if changed), watch for changes and start the web server on http://localhost:5000
  • Run Webpack dev middleware with HMR via ASP.NET JavaScriptServices

npm run migrate

After making changes to Entity Framework models in api/Models/, run this command to generate and run a migration on the database. A timestamp will be used for the migration name.

npm test

This will run the xUnit tests in api.test/ and the Mocha/Enzyme tests in client-react.test/.

npm run provision:prod

Before running this script, you need to create an ops/hosts file first. See the ops README for instructions.

This will run the ops/provision.yml Ansible playbook and provision hosts in ops/hosts inventory file. This prepares the hosts to recieve deployments by doing the following:

  • Install Nginx
  • Generate a SSL certificate from Let's Encrypt and configure Nginx to use it
  • Install .Net Core
  • Install Supervisor (will run/manage the ASP.NET app)
  • Install PostgreSQL
  • Setup a cron job to automatically backup the PostgresSQL database, compress it, and upload it to S3.
  • Setup UFW (firewall) to lock everything down except inbound SSH and web traffic
  • Create a deploy user, directory for deployments and configure Nginx to serve from this directory

npm run deploy:prod

Before running this script, you need to create a ops/hosts file first. See the ops README for instructions.

This script will:

  • Build release Webpack bundles
  • Package the .NET Core application in Release mode (dotnet publish)
  • Run the ops/deploy.yml Ansible playbook to deploy this app to hosts in /ops/hosts inventory file. This does the following:
  • Copies the build assets to the remote host(s)
  • Updates the appsettings.json file with PostgresSQL credentials specified in ops/hosts file and the app URL (needed for JWT tokens)
  • Restarts the app so that changes will be picked up

Development Email Delivery

This template includes a MailCatcher Docker image so that when email is sent during development (i.e. new user registration), it can be viewed in the MailCacher web interface at http://localhost:1080/.

Visual Studio Code config

This project has Visual Studio Code tasks and debugger launch config located in .vscode/.

Tasks

  • Command+Shift+B - Runs the "build" task which builds the api/ project
  • Command+Shift+T - Runs the "test" task which runs the xUnit tests in api.test/ and Mocha/Enzyme tests in client-react.test/.

Debug Launcher

With the following debugger launch configs, you can set breakpoints in api/ or the the Mocha tests in client-react.test/ and have full debugging support.

  • Debug api/ (server) - Runs the vscode debugger (breakpoints) on the api/ .NET Core app
  • Debug client-react.test/ (Mocha tests) - Runs the vscode debugger on the client-react.test/ Mocha tests

Credit

The following resources were helpful in setting up this template:

aspnet-core-react-template's People

Contributors

bradymholt avatar w9n avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.