Official Seatsupply data API.
This project was bootstraped with Node.js API Starter Kit
- Docker, Node.js, Yarn, JavaScript, Babel, Flow, Prettier — core platform and dev tools
- Express, Passport.js, session, flash, cors etc. — common HTTP-server features
- GraphQL.js, GraphQL.js Relay, DataLoader, validator — GraphQL schema and API endpoint
- PostgreSQL, Redis, Knex, pg — SQL, document, key/value data store; data acess and migrations
- Nodemailer, Handlebars, Juice — transactional email and email templates /w layout support
- I18next, I18next Middleware, I18next Backend — localization and translations
- Jest - unit and snapshot testing
.
├── /build/ # The compiled output (via Babel)
├── /locales/ # Localization resources (i18n)
├── /migrations/ # Database schema migrations
├── /seeds/ # Scripts with reference/sample data
├── /src/ # Node.js application source files
│ ├── /emails/ # Handlebar templates for sending transactional email
│ ├── /routes/ # Express routes, e.g. /login/facebook
│ ├── /schema/ # GraphQL schema type definitions
│ ├── /utils/ # Utility functions (mapTo, mapToMany etc.)
│ ├── /app.js # Express.js application
│ ├── /Context.js # Data loaders and other context-specific stuff
│ ├── /db.js # Database access and connection pooling (via Knex)
│ ├── /email.js # Client utility for sending transactional email
│ ├── /errors.js # Custom errors and error reporting
│ ├── /passport.js # Passport.js authentication strategies
│ ├── /redis.js # Redis client
│ ├── /server.js # Node.js server (entry point)
│ └── /types.js # Flow type definitions
├── /tools/ # Build automation scripts and utilities
├── docker-compose.yml # Defines Docker services, networks and volumes
├── docker-compose.override.yml # Overrides per developer environment (not under source control)
├── Dockerfile # Commands for building a Docker image for production
├── package.json # List of project dependencies
└── postgres-initdb.sh # Configuration script for the PostgreSQL Docker container
- Docker Community Edition v17 or higher
- VS Code editor (preferred) + Project Snippets, EditorConfig, ESLint, Flow, and Prettier plug-ins.
Just clone the repo, edit the environment variables in the docker-compose file, and run docker-compose up
:
git clone https://github.com/castlesb/seatsupply-api.git example-api
cd example-api # Change current directory to the newly created one
docker-compose up # Launch Docker containers with the Node.js API app running inside
The API server must become available at http://localhost:8080/graphql.
Once the Docker container named api
is started, the Docker engine executes node tools/run.js
command that installs Node.js dependencies, migrates database schema to the latest version,
compiles Node.js app from source files (see src
) and launches it with "live reload"
on port 8080
.
If you need to manually rollback and re-apply the latest database migration file, run the following:
yarn docker-db-rollback # Rollbacks the latest migration
yarn docker-db-migrate # Migrates database to the latest version (see /migrates folder)
yarn docker-db-seed # Seeds database with test data (see /seeds folder)
In order to open a shell from inside the running "api" container, run:
docker-compose exec api /bin/sh
Similarly, if you need to open a PostgreSQL shell (psql), execute this command:
docker-compose exec db psql <db> -U postgres
For the full list of automation scripts available in this project, please reffer to "scripts"
section in the package.json
file and the tools
folder.
yarn lint # Find problematic patterns in code
yarn check # Check source code for type errors
yarn docker-test # Run unit tests once inside a Docker container
yarn docker-test-watch # Run unit tests in watch mode inside a Docker container
For more information visit http://facebook.github.io/jest/
In order to run the app with V8 inspector enabled, simply replace node tools/run.js
with node --inspect=0.0.0.0:9229 tools/run.js
in either docker-compose.yml
file or, even better, in docker-compose.override.yml
. Then restart the app (docker-compose up
) and
attach your debugger to 127.0.0.1:9230
(see .vscode/launch.json
)
If you keep the original Git history after cloning this repo, you can always fetch and merge the recent updates back into your project by running:
git remote add seatsupply-api https://github.com/castlesb/seatsupply-api.git
git checkout master
git fetch seatsupply-api
git merge seatsupply-api/master
docker-compose build --no-cache
docker-compose run --rm --no-deps api yarn
docker-compose up
NOTE: Try to merge as soon as the new changes land on the master branch in Seatsupply API repository, otherwise your project may differ too much from the base/upstream repo.
Customize the deployment script found in tools/publish.js
if needed. Then whenever you need to
deploy your app to a remote server simply run:
node tools/publish <host> # where <host> is the name of your web server (see ~/.ssh/config)
Made with ♥ by Brian Castles