mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -07:00
@@ -59,3 +59,4 @@ docs
|
||||
|
||||
.nyc_output
|
||||
coverage
|
||||
database/
|
||||
|
||||
@@ -22,23 +22,26 @@ It makes the following modifications:
|
||||
|
||||
- Configured for Travis CI (continuous integration), Coveralls (code coverage), GreenKeeper (automated dependency management), and Semantic Release (automated versioning).
|
||||
|
||||
- 'Production' environment is targeted for packaging as a Docker container.
|
||||
|
||||
## Features
|
||||
This project covers basic necessities of most APIs.
|
||||
* Authentication (passport & jwt)
|
||||
* Database (mongoose)
|
||||
* Testing (mocha)
|
||||
* Doc generation with apidoc
|
||||
* linting using standard
|
||||
* Linting using standard
|
||||
* Packaged as a Docker container
|
||||
|
||||
|
||||
|
||||
## Requirements
|
||||
* node __^8.9.4__
|
||||
* npm __^5.7.1__
|
||||
* node __^10.15.1__
|
||||
* npm __^6.7.0__
|
||||
|
||||
## Installation
|
||||
```bash
|
||||
git clone https://github.com/christroutner/babel-free-koa2-api-boilerplate.git
|
||||
git clone https://github.com/christroutner/koa-api-boilerplate/tree/docker
|
||||
```
|
||||
|
||||
## Structure
|
||||
@@ -53,6 +56,9 @@ git clone https://github.com/christroutner/babel-free-koa2-api-boilerplate.git
|
||||
│ │ └── test.js
|
||||
│ ├── index.js # Config entrypoint - exports config according to envionrment and commons
|
||||
│ └── passport.js # Passportjs config of strategies
|
||||
|
|
||||
├── production # Dockerfile for build production container
|
||||
|
|
||||
├── src # Source code
|
||||
│ ├── modules
|
||||
│ │ ├── controller.js # Module-specific controllers
|
||||
@@ -68,6 +74,8 @@ git clone https://github.com/christroutner/babel-free-koa2-api-boilerplate.git
|
||||
* `npm run dev` Start server on dev mode with nodemon
|
||||
* `npm run docs` Generate API documentation
|
||||
* `npm test` Run mocha tests
|
||||
* `docker-compose build` Build a 'production' Docker container
|
||||
* `docker-compose up` Run the docker container
|
||||
|
||||
## Documentation
|
||||
API documentation is written inline and generated by [apidoc](http://apidocjs.com/).
|
||||
|
||||
+2
-1
@@ -42,7 +42,8 @@ async function startServer () {
|
||||
modules(app)
|
||||
|
||||
// Enable CORS for testing
|
||||
// app.use(cors({origin: '*'}))
|
||||
// THIS IS A SECURITY RISK. COMMENT OUT FOR PRODUCTION
|
||||
app.use(cors({ origin: '*' }))
|
||||
|
||||
// MIDDLEWARE END
|
||||
|
||||
|
||||
Vendored
+4
-3
@@ -1,6 +1,7 @@
|
||||
// export default {
|
||||
// port: process.env.PORT || 5000
|
||||
// }
|
||||
/*
|
||||
This file is used to store unsecure, application-specific data common to all
|
||||
environments.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
port: process.env.PORT || 5000
|
||||
|
||||
Vendored
+4
-6
@@ -1,13 +1,11 @@
|
||||
/*
|
||||
export default {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-dev'
|
||||
}
|
||||
These are the environment settings for the DEVELOPMENT environment.
|
||||
This is the environment run by default with `npm start` if KOA_ENV is not
|
||||
specified.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-dev'
|
||||
database: 'mongodb://localhost:27017/koa-server-dev'
|
||||
}
|
||||
|
||||
Vendored
+7
-6
@@ -1,13 +1,14 @@
|
||||
/*
|
||||
export default {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-prod'
|
||||
}
|
||||
These are the environment settings for the PRODUCTION environment.
|
||||
This is the environment run with `npm start` if KOA_ENV=production.
|
||||
This is the environment run inside the Docker container.
|
||||
|
||||
It is assumed the MonogDB Docker container is accessed by port 5555
|
||||
so as not to conflict with the default host port of 27017 for MongoDB.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-prod'
|
||||
database: 'mongodb://172.17.0.1:5555/koa-server-prod'
|
||||
}
|
||||
|
||||
Vendored
+4
-6
@@ -1,13 +1,11 @@
|
||||
/*
|
||||
export default {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-test'
|
||||
}
|
||||
These are the environment settings for the TEST environment.
|
||||
This is the environment run with `npm start` if KOA_ENV=test.
|
||||
This is the environment run by the test suite.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
session: 'secret-boilerplate-token',
|
||||
token: 'secret-jwt-token',
|
||||
database: 'mongodb://localhost:27017/p2pvps-server-test'
|
||||
database: 'mongodb://localhost:27017/koa-server-test'
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
const common = require('./env/common')
|
||||
|
||||
const env = process.env.NODE_ENV || 'development'
|
||||
const env = process.env.KOA_ENV || 'development'
|
||||
const config = require(`./env/${env}`)
|
||||
|
||||
module.exports = Object.assign({}, common, config)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
This is where the mongodb docker container stores its db files.
|
||||
@@ -0,0 +1,23 @@
|
||||
# Start the testnet server with the command 'docker-compose up -d'
|
||||
|
||||
koa-mongodb:
|
||||
image: mongo
|
||||
ports:
|
||||
- "5555:27017" # <host port>:<container port>
|
||||
volumes:
|
||||
- ./database:/data/db
|
||||
command: mongod --smallfiles --logpath=/dev/null # -- quiet
|
||||
restart: always
|
||||
|
||||
koa:
|
||||
build: ./production/
|
||||
dockerfile: Dockerfile
|
||||
links:
|
||||
- koa-mongodb
|
||||
ports:
|
||||
- "5000:5000" # <host port>:<container port>
|
||||
volumes:
|
||||
# - ./logs:/home/coinjoin/consolidating-coinjoin/logs
|
||||
- ./keys:/home/safeuser/keys
|
||||
|
||||
restart: always
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "NODE_ENV=test nyc --reporter=text ./node_modules/.bin/mocha --exit",
|
||||
"test": "KOA_ENV=test nyc --reporter=text ./node_modules/.bin/mocha --exit",
|
||||
"lint": "eslint src/**/*.js",
|
||||
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Create a Dockerized API server
|
||||
#
|
||||
|
||||
#IMAGE BUILD COMMANDS
|
||||
# ct-base-ubuntu = ubuntu 18.04 + nodejs v10 LTS
|
||||
FROM christroutner/ct-base-ubuntu
|
||||
MAINTAINER Chris Troutner <chris.troutner@gmail.com>
|
||||
|
||||
#Create the user 'safeuser' and add them to the sudo group.
|
||||
#RUN useradd -ms /bin/bash safeuser
|
||||
#RUN adduser safeuser sudo
|
||||
|
||||
#Set password to 'password' change value below if you want a different password
|
||||
#RUN echo safeuser:password | chpasswd
|
||||
|
||||
#Set the working directory to be the home directory
|
||||
WORKDIR /home/safeuser
|
||||
|
||||
#Setup NPM for non-root global install
|
||||
#RUN mkdir /home/safeuser/.npm-global
|
||||
#RUN chown -R safeuser .npm-global
|
||||
#RUN echo "export PATH=~/.npm-global/bin:$PATH" >> /home/safeuser/.profile
|
||||
#RUN runuser -l safeuser -c "npm config set prefix '~/.npm-global'"
|
||||
|
||||
# Expose the port the API will be served on.
|
||||
EXPOSE 5000
|
||||
|
||||
# Switch to user account.
|
||||
USER safeuser
|
||||
# Prep 'sudo' commands.
|
||||
RUN echo 'abcd8765' | sudo -S pwd
|
||||
|
||||
# Clone the rest.bitcoin.com repository
|
||||
WORKDIR /home/safeuser
|
||||
RUN git clone https://github.com/christroutner/koa-api-boilerplate
|
||||
RUN mv koa-api-boilerplate koa
|
||||
RUN mkdir keys
|
||||
|
||||
# Switch to the desired branch. `master` is usually stable,
|
||||
# and `stage` has the most up-to-date changes.
|
||||
WORKDIR /home/safeuser/koa
|
||||
|
||||
# For development: switch to unstable branch
|
||||
RUN git checkout docker
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
VOLUME /home/safeuser/keys
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
# Start the application.
|
||||
COPY start-production start-production
|
||||
CMD ["./start-production"]
|
||||
|
||||
#CMD ["npm", "start"]
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
export KOA_ENV=production
|
||||
npm start
|
||||
Reference in New Issue
Block a user