Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
DEV-147 added basic framework for API server and database connection …
Browse files Browse the repository at this point in the history
…with roles and users
  • Loading branch information
davesag committed Feb 27, 2018
1 parent f998f7d commit 4b2d1fd
Show file tree
Hide file tree
Showing 36 changed files with 7,916 additions and 8 deletions.
80 changes: 80 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2

jobs:
build:
docker:
- image: circleci/node:9.6.1
- environment:
- NODE_ENV: test
- DB_USER: root
- DB_PASS: test
- DB_HOST: 127.0.0.1
- DB_NAME: circle-test

- image: circleci/postgres:9.6.2-alpine
- environment:
- POSTGRES_USER: root
- POSTGRES_PASS: test
- POSTGRES_DB: circle-test

steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: Postgres Client
command: sudo apt install postgresql-client

- run:
name: Install global packages
command: sudo npm install -g truffle codecov greenkeeper-lockfile@1

- run:
name: Greenkeeper Lockfile
command: greenkeeper-lockfile-update

- run:
name: Install dependencies
command: npm install

- save_cache:
key: v1-dependencies-{{ checksum "package.json" }}
paths:
- node_modules

- run:
name: Javascript Linter
command: npm run lint

- run:
name: Unit Tests
command: npm test

- run:
name: Database Tests
command: npm run test:db

- run:
name: Server Tests
command: npm run test:server

# - run:
# name: Unit tests with code coverage
# command: npm run test:cov
#
- run:
name: Push any lockfile changes
command: greenkeeper-lockfile-upload

# - run:
# name: Send reports to codecov.io
# command: codecov
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": ["standard", "prettier", "prettier/standard"],
"plugins": ["prettier", "standard", "mocha"],
"parserOptions": {
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"mocha": true
},
"rules": {
"prettier/prettier": ["error", { "singleQuote": true, "semi": false }]
}
}
9 changes: 9 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// can't be in ES6 syntax

var path = require('path');

module.exports = {
'config': path.resolve(__dirname, 'config', 'config.json'),
'migrations-path': path.resolve(__dirname, 'migrations'),
'models-path': path.resolve(__dirname, 'src', 'models')
}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM 'node:9-alpine'
MAINTAINER 'Dave Sag <[email protected]>'

RUN apk add --update postgresql-client

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

# Build code for development
RUN npm install

# Bundle app source
COPY . .

# expose the port
EXPOSE 3000

# start it
CMD [ "npm", "start" ]
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ The main C4Coin Public facing website

_add details_

### API Routes

#### `GET /ping`

Returns a heartbeat response.

{
"response": "okay"
}

#### `GET /api/v1`

_fill the rest of this in_

## Development

_add details_
Expand All @@ -25,21 +39,36 @@ _add details_

npm install

### Testing
### To Start the API server while working on API clients.

docker-compose up -d

Runs the database and server within docker, exposing the API on port `3001`.

### To Start the server to work on the server itself

npm install

Run `docker-compose up -d db` to only start Postgres,

Then run `npm start` to start the api server on port `3000`

Run unit tests with
### Seed some data

npm test
With the database running, run

or with code coverage
I_KNOW_WHAT_I_AM_DOING=true npm run seed

npm run test:cov
### Test it

Run integration tests with
run `docker-compose up db -d` to only start Postgres, then:

nom run test:integration
* `npm test` — runs the unit tests (quick)
* `npm run test:db` — runs the database tests (not so quick)
* `npm run test:server` — runs the API endpoint tests (not so quick)
* `npm run test:db` — runs all the tests (slowest of all)

### Linting
### Lint it

npm run lint

Expand Down
23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "docker",
"password": "docker",
"database": "c4coin-api-cs-dev",
"host": "localhost",
"dialect": "postgres"
},
"test": {
"username": "docker",
"password": "docker",
"database": "c4coin-api-cs-test",
"host": "localhost",
"dialect": "postgres"
},
"production": {
"username": "docker",
"password": "docker",
"database": "c4coin-api-cs-prod",
"host": "localhost",
"dialect": "postgres"
}
}
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3"
volumes:
# We'll define a volume that will store the data from the postgres databases:
postgres-data:
driver: local

services:
db:
# replace username/repo:tag with your name and image details
image: postgres:9.6.2
ports:
- 5432:5432
volumes:
- postgres-data:/var/lib/postgresql
healthcheck:
test: "exit 0"
environment:
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
networks:
- apiserver
server:
build: .
ports:
- 3001:3000
links:
- db
depends_on:
- db
healthcheck:
test: "exit 0"
environment:
DB_USER: docker
DB_PASS: docker
DB_HOST: db
command: ["./start.sh", "db", "npm", "start"]
networks:
- apiserver

networks:
apiserver:
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Server = require("./src/server")

process.on("unhandledRejection", (reason, p) => {
// eslint-disable-next-line no-console
console.log("Unhandled rejection in promise", p, "caused by", reason)
})

Server.start()
Loading

0 comments on commit 4b2d1fd

Please sign in to comment.