Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Production ready full stack starter kit. Featuring: Docker, Node, Postgres, Sequelize, React, Redux, GraphQL, RXjs, Webpack 3, Hot Module Reloading, Server Side Rendering and Code Splitting.

License

NotificationsYou must be signed in to change notification settings

Alex-ray/docker-postgres-react-redux-graphql-hmr-ssr-kit

Repository files navigation

💭 What is it?

This is a meta framework, framework. A project made up of specific technologies that are easily interchangable.

Docker: - This is where our stack starts our app is split up into three containers an Nginx container for serving static files, a Node.js container for the backend and a Postgres container for our database. This also enables for cross platform development and deployment. Robust, Flexible and Dead Simple.

Postgres: - The tried, trued and tested defacto databse. In this project I use the popular sequelize ORM.

GraphQL: - A more effecient way to query data from a server. A better way to develop with the interactive graphql interface. This also provides an abstraction layer between our api and database that provides additional flexiblity if we every need to swap it out.

React, Redux, React Router: - At this point its almost and industry standard. Undirectional data flow, fast render times and extremely flexible.

Redux Observables (Rxjs): - RxJS 5-based middleware for Redux. Compose and cancel async actions to create side effects and more.

Server Side Rendering: - We use server side rending by utilizing Universal javascript on the Node.js server. Because were using React its simply a matter of rendering React views on the server.

Code Splitting: - Split code into bundles so that code is asynchronously loaded by the client.

Hot Module Reloading: - Replaces modules that have been changed in real time while preserving the state.

⚙ How?

The application works like this.

We use shell scripts to handle docker and related tasks, these are located in thebin directory. e.x../bin/develop.sh or./bin/deploy.sh (more details on this below)

The shell scripts sets up our docker containers, migrates the database, installs dependencies, compiles source code and launches our servers.

The Nginx server handles static file requests and the Node.js Express server handles all other request. When a request is made we render our React application on the server based on that route and return the output as a html.

Once the Html is sent to the client our React application takes over.

On build our application is split up into bundles for each route. Only that routes bundle is served to the client; when a new route is entered a new bundle is requested and sent to the client.

In addition our core dependencies are split into a seperate bundles and cached our our Nginx server. Everything is fingerprinted.

When developing we spin up a seperate frontend server that handles hot module reloading.

On a more techinical note we use all sorts of goodies that I leave you to explore, things likereselect,redux-actions,immutablejs,cssnext,react-router-redux etc...

Last but not least I have to give a huge shout out to @Producters for thehttps://github.com/Producters/docker-node-react-starter which is what this project is based off of.

🛠 Setup

Get latest docker (1.11+) & docker-compose (1.7+):
https://www.docker.com/
https://docs.docker.com/compose/

Pull down the repository:

git clone git@github.com:Alex-ray/docker-postgres-react-redux-graphql-hmr-ssr-kit.git

Start the dev server:

./bin/develop.sh

Wait for docker to set up dev env, then openhttp://localhost:8000

production mode

# build production images, create db backup & start./bin/deploy.sh# stop server./bin/stop_production.sh# start srever./bin/start_production.sh

In prod mode sources are added to docker image rather than mounted from host. Nginx serves static files, proxy pass to node for app. Logs inlogs dir.

enable ssl

Copy your .key and .crt files tonginx/ssl and run./bin/deploy.sh.

install dependencies

# frontend./bin/npm_frontend.sh install [package] --save-dev# backend./bin/npm_backend.sh install [package] --save

database management

# open psql session./bin/psql.sh# create a backup in backups dir./bin/backup.sh# restore from a backup in backups dir (server must be stopped)./bin/restore.sh backups/somebackup.bak

layout

bin/                          - various utility scriptsdocker-compose.yml            - base docker compose configdocker-compose.overrides.yml  - development docker compose configdocker-compose.production.yml - production docker compose configfrontend/                     - frontend stufffrontend/package.json         - npm package file with frotnend dependenciesfrontend/dist/                - compiled and production ready client side codefrontend/universal/           - universal javascript codefrontend/index.js             - js entry point. include other js deps herebackend/                      - backend stuffbackend/lib/                  - node appbackend/lib/index.js          - entry pointbackend/lib/models/           - sequelize model definitionsbackend/lib/migrations/       - sequelize migrationsbackend/config/               - configbackend/config/default.json   - config defaultsbackend/views/                - pug templatesbackend/Dockerfile            - production build dockerfilebackend/media/                - user uploads @TODObackend/package.json          - npm pacakge file with backend & test deposbackend/nightwatch.json       - nigthwatch configbackend/tests/specs/*         - nightwatch test specslogs/                         - in prod mode app, nginx logs go herenginx/                        - nginx stuff for prod modenginx/ssl/                    - put key & cert here if you use sslnginx/nginx_nossl.conf        - nginx conf if no ssl is usednginx/nginx_ssl.conf          - nginx conf for deploy with ssl

config

Config files for backend are located atconfig/*.json.
Ifconfig/[NODE_ENV].json exists, values are loaded from it first. Then defaults are filled in fromconfig/default.json;

logging

Winston is used for logging. Loggers and transport are configured via config files, seeconfig/default.json.

importlogger,{getLogger}from'winston';//default loggerlogger.info('logging to default');logger.error('bad thing happened');//custom logger, define transports in configletnetlogger=getLogger('network');netlogger.info('network stuff');

migrations

# create new migration./bin/sequelize.sh migration:create --name some_migration# run migrations./bin/sequelize.sh db:migrate

tests

e2e tests are implemented usingnightwatch.js. Test specs are located atbackend/tests/specs/

#run tests./bin/test.sh# skip frontend build (eg, running tests repeatedly)./bin/test.sh --skipbuild# keep selenium, vnc server & database running after tests end# for fast next run & to keep vnc from disconnecting if debuggin./bin/test.sh --dontstop# run a particular test file only./bin/test.sh -- --test tests/specs/auth.js# run particular test case only./bin/test.sh -- --test tests/specs/auth.js --testcase'User can login via auth0'

To debug tests it's possible to vnc into selenium container while its running at localhost:5900 and view the browser. Password issecret.

sudo apt-get install vinagre# vnc clientvinagre localhost:5900

About

Production ready full stack starter kit. Featuring: Docker, Node, Postgres, Sequelize, React, Redux, GraphQL, RXjs, Webpack 3, Hot Module Reloading, Server Side Rendering and Code Splitting.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp