AdamZaczek / Docker-Auth-Jwt-GraphQL

This is a playground repo, used to see how stuff works

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tech Stack

Directory Layout

.
├── /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
│   ├── /__tests__/             # Unit tests (Jest)
│   ├── /emails/                # Handlebar templates for sending transactional email
│   ├── /routes/                # Express routes, e.g. /login/facebook
│   ├── /schema/                # GraphQL schema, types, fields and mutations
│   │   ├── /Node.js            # Relay's "node" definitions
│   │   ├── /User.js            # User related top-level fields and mutations
│   │   ├── /UserType.js        # User type, representing a user account (id, emails, etc.)
│   │   ├── /...                # etc.
│   │   └── /index.js           # Exports GraphQL schema object
│   ├── /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)
├── /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

Prerequisites

Getting Started

Just clone the repo and run docker-compose up:

git clone https://github.com/kriasoft/nodejs-api-starter.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
yarn docker-db-seed             # Seed the database with some test data

The API server must become available at http://localhost:8080/graphql (live demo).

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.

To list all the containers simply run

docker ps -a

Testing

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/

Debugging

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)

Keeping Up-to-Date

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 nodejs-api-starter https://github.com/kriasoft/nodejs-api-starter.git
git checkout master
git fetch nodejs-api-starter
git merge nodejs-api-starter/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 Node.js API Starter repository, otherwise your project may differ too much from the base/upstream repo.

Deployment

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)

Not sure where to deploy your app? DigitalOcean is a great choice in many cases (get $10 credit)

Reference Articles and Tutorials

About

This is a playground repo, used to see how stuff works

License:MIT License


Languages

Language:JavaScript 78.9%Language:HTML 20.7%Language:Shell 0.4%