• Stars
    star
    620
  • Rank 71,978 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ASP.NET Core 3.1 / React SPA Template App

ASP.NET Core / React SPA Template App


 Would you take a quick second and ⭐️ my repo?


This app is a template application using ASP.NET Core 3.1 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 3.1
    • PostgreSQL 10
    • Entity Framework Core w/ EF Migrations
    • JSON Web Token (JWT) authorization
    • Docker used for development PostgreSQL database and MailCatcher server
  • Client
    • React 16
    • 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, PostgreSQL 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 (for development) as well. If you experience any issues getting it to run on Windows and work through them, please submit a PR! The production provisioning and deployment scripts (provision:prod and deploy:prod) use Ansible and require a Linux/Ubuntu >= 16.04 target host.

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/config.yml 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. Ubuntu 16.04 (Xenial) and Ubuntu 18.04 (Bionic) is supported and tested.

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 PostgreSQL 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/config.yml 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/config.yml inventory file.

This does the following:

  • Copies the build assets to the remote host(s)
  • Updates the appsettings.json file with PostgreSQL credentials specified in ops/group_vars/all file and the app URL (needed for JWT tokens)
  • Restarts the app so that changes will be picked up

Entity Framework Migrations are automatically applied upon startup so they will run when the app restarts.

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/.

Older Versions

This template was originally created on .NET Core 1.0 and has been upgraded with new versions of .NET Core. Older versions can be found on the Releases page.

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:

More Repositories

1

cRonstrue

JavaScript library that translates Cron expressions into human readable descriptions
TypeScript
994
star
2

cron-expression-descriptor

A .NET library that converts cron expressions into human readable descriptions.
C#
903
star
3

aspnet-core-vuejs-template

ASP.NET Core / Vue.js SPA Template App
C#
79
star
4

ansible-rails

Ansible playbook for provisioning and deploying a Rails/MySQL app to an Ubuntu server
Jinja
72
star
5

koa-vuejs-template

Koa / Vue.js SPA Template App
TypeScript
53
star
6

smartthings-rest-api

SmartThings REST API
Groovy
51
star
7

dbup-sqlserver-scripting

SQL Server object definition scripting for DbUp
C#
44
star
8

vscode-pgFormatter

A VS Code extension that formats PostgresSQL SQL
TypeScript
41
star
9

dotfiles

My system configuration for macOS, consisting of config dotfiles and shell scripts
Vim Script
38
star
10

jquery-googleslides

A jQuery plugin to display your Google Photos.
HTML
23
star
11

jBash

Helpers for Bash like shell scripting in JavaScript
JavaScript
21
star
12

jsh

Helpers for Bash like shell scripting in JavaScript
TypeScript
15
star
13

tiger-provisioning

Ansible provisioning for the Raspberry Pi running ArchLinux ARM sitting in my closet
Shell
12
star
14

dbup-consolescripts

Package Manager Console scripts for DbUp
PowerShell
11
star
15

npm-github-release

Automates the full release process for npm packages
JavaScript
11
star
16

debt-paydown-calculator

Compare methods to payoff your debt
TypeScript
10
star
17

vuejs-test-mocha-typescript-example

Example unit testing vue-class-component Vue.js components with Mocha and TypeScript
JavaScript
9
star
18

openbank

A friendly REST service wrapper for OFX bank servers.
JavaScript
9
star
19

postgraphile-playground

A web app using PostGraphile
JavaScript
8
star
20

raspberrypi-relay-controller

An Ansible playbook to provision a Raspberry Pi as a 2-channel relay control server
Groovy
8
star
21

pedamorf

A PDF conversion server for Windows that supports documents, text, images, html and urls.
C#
8
star
22

vistaicm-server

A Node.js app that works with the VISTA-ICM module to monitor and control a Honeywell VISTA alarm panel.
HTML
8
star
23

veritas

A web application for social groups to share contact info, calendar events, track attendance and more.
Ruby
7
star
24

ynab-utils

Some miscellaneous utilities for YNAB
TypeScript
6
star
25

picasawebsync

Synchronizes local photos and videos to online Picasa Web Albums
C#
6
star
26

test-microphone

A simple web app to test your microphone
HTML
6
star
27

sveltekit-auth-template

TypeScript
5
star
28

bank-alerts-to-ynab

This project routes spending alert emails from your bank to YNAB so your transactions appear in YNAB seconds after they occur.
JavaScript
5
star
29

psqlformat

A PostgreSQL SQL syntax formatter
TypeScript
5
star
30

franz-recipe-basecamp

Basecamp recipe for Franz
JavaScript
5
star
31

geekytidbits.com

My Geeky Blog
Handlebars
4
star
32

ynab-api-webhooks

Webhooks for the YNAB API
TypeScript
4
star
33

vue-typescript-bulma-template

A Vue.js template using TypeScript and Bulma
JavaScript
4
star
34

vscode-debugging-ts-code

Demo project showing how to debug TypeScript in VSCode using ts-node
TypeScript
3
star
35

docker-postgresql-northwind

A PostgreSQL server with the Northwind sample database
TSQL
3
star
36

ts-progressive-convert-namespace-modules

Example of progression conversion from TypeScript namespaces to modules
TypeScript
3
star
37

the-painting-app

A painting app my 6 year-old daughter and I made together
HTML
2
star
38

xertz

A static site generator written in TypeScript
TypeScript
2
star
39

covid19-chart

A COVID-19 D3.js line chart comparing cases between 2 countries
HTML
2
star
40

treasure-castle

A simple text based game used as a teaching tool for my daughter and her friend Noah
JavaScript
2
star
41

google-action-tiger

A Google Assistant Action (with an invocation name of "tiger") which controls a Honeywell VISTA-20P alarm panel and opens/closes garage doors
JavaScript
2
star
42

atx-node-typescript

Examples for 'A Fresh Look at TypeScript' (Austin Node.js; 10/16/2019)
2
star
43

cos-js-typescript

Examples for 'A Fresh Look at TypeScript' (coloradoSprings.js; 05/26/2021)
1
star
44

rabbitmq-email

A RabbitMQ Docker image that has SMTP support for incoming and outgoing email
Dockerfile
1
star
45

syndication-fetcher

A RSS and Atom feed parser
TypeScript
1
star
46

auto-import-ynab-transactions

Setup a recurring scheduled job to automatically import your YNAB transactions
1
star
47

bento-budget-app

Bento Budget - Envelope based budgeting web application
Ruby
1
star
48

home-assistant-config

My configuration for Home Assistant
1
star
49

franz-recipe-github-notifications

Basecamp recipe for GitHub Notifications
JavaScript
1
star
50

vuejs-playground

A playground for learning Vue.js
JavaScript
1
star
51

alexa-guitar-ace

An Alexa Skill that helps you tune and plays chords on your guitar
JavaScript
1
star