Skip to content

A boilerplate with TypeScript + React + Redux + redux-saga on the front, .NET Core on the back, all in a Docker container

License

Notifications You must be signed in to change notification settings

robbie-c/boilerplate-typescript-react-redux-netcore-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A boilerplate with TypeScript + React + Redux + redux-saga on the front, .NET Core on the back, all in a Docker container

Overview

I started off using

dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

which let me generate a TypeScript React/Redux project with

dotnet new reactredux

Unfortunately it uses redux-thunk and I didn't like how the code was structured, so I ported it over to redux-sagas and a better project layout.

Regarding server-side rendering, currently it does this but doesn't include any API calls. This is because I haven't added any auth code yet, which is one of the trickier things to get right with server-side rendering and API calls.

Currently API calls for page loading are handled by sagas that are triggered by actions dispatched on life cycle functions (e.g. ComponentDidMount)

Links

TODO

  • Convert either TS types to C# or vice versa, so we can type check across API calls
  • Authentication
  • Database connection (probably PostgreSQL)
  • Server side api calls (needs auth first). Instead of loading data via React lifecycle functions I suspect this is best handled by somehow pairing components/routes to a saga, and running all relevant ones before return for server side rendering.

Usage

Production:

docker build -f docker/prod.dockerfile -t prodimage .
docker run -p 5000:5000 prodimage

Go to locahost:5000

Development

To spin up images for the db, web server, and misc dev

# Foreground:
docker-compose up
# Background (the d stands for daemon):
docker-compose up -d

To run migrations on the db

docker-compose exec db psql -U docker -f /app/Migrations/2017-06-05-18\:35\:02-Up-InitialSetup.sql

Once this is running, you can go to locahost:5000 and you can even update the front end code and watch it live update.

To execute a command inside a running container, do

docker-compose exec NAME CMD
# e.g. to get bash inside the dev image
docker-compose exec dev bash

To do back end development, i.e. be able to change C# files and rapidly restart the server, you will need to stop web container and get bash in the dev container.

docker-compose stop web
docker-compose exec dev bash

Then once in that container, you can use the dotnet command as usual, e.g.

dotnet restore
dotnet publish
dotnet run

Go to locahost:5001 rather than port 5000 for the result of what is served inside the dev image.

About

A boilerplate with TypeScript + React + Redux + redux-saga on the front, .NET Core on the back, all in a Docker container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published