| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- const Inert = require('@hapi/inert')
- const Vision = require('@hapi/vision')
- const Confidence = require('@hapipal/confidence')
- const Schwifty = require('@hapipal/schwifty')
- const HapiSwagger = require('hapi-swagger')
-
- const confs = {
- local: {
- db: process.env.DB_NAME,
- host: process.env.DB_HOST,
- port: process.env.DB_PORT,
- ssl: false,
- user: process.env.DB_USER,
- pw: process.env.DB_ROOT_PASSWORD,
- },
- prod: {
- db: process.env.PSCALE_DB_NAME,
- host: process.env.PSCALE_DB_HOST,
- port: process.env.PSCALE_DB_PORT,
- branch: process.env.PSCALE_DB_BRANCH,
- ssl: true,
- user: process.env.PSCALE_DB_USER,
- pw: process.env.PSCALE_DB_PASSWORD,
- },
- dbFlavor: process.env.DB_TYPE,
- }
-
- const isProd = () => (process.env.USE_LOCAL_DB == 'true' ? 'local' : 'prod')
- const connection = {
- database: confs[isProd()].db,
- host: confs[isProd()].host,
- port: confs[isProd()].port,
- ssl: confs[isProd()].ssl,
- user: confs[isProd()].user,
- password: confs[isProd()].pw,
- }
-
- /** Glue manifest as a confidence store */
- module.exports = new Confidence.Store({
- server: {
- host: process.env.API_HOST,
- port: {
- $filter: 'NODE_ENV',
- $default: {
- $param: 'API_PORT',
- $coerce: 'number',
- $default: process.env.API_PORT,
- },
- test: { $value: undefined }, // Let the server find an open port
- },
- debug: {
- $filter: 'NODE_ENV',
- $default: {
- log: ['error', 'start'],
- request: ['error'],
- },
- production: {
- request: ['implementation'],
- },
- },
- },
- register: {
- plugins: [
- /** Main app */
- {
- plugin: '../lib',
- routes: {
- prefix: '/api',
- },
- options: {
- jwtKey: {
- $filter: 'NODE_ENV',
- $default: {
- $param: 'APP_SECRET',
- $default: 'app-secret',
- },
- // Use .env file in production
- production: {
- $param: 'APP_SECRET',
- },
- },
- },
- },
- /** Documentaion plugins */
- Inert,
- Vision,
- {
- plugin: HapiSwagger,
- options: {
- info: { title: 'Test API Documentation' },
- },
- },
- /** Model and knex integration */
- {
- plugin: Schwifty,
- options: {
- $filter: 'NODE_ENV',
- $default: {},
- $base: {
- migrateOnStart: true,
- knex: {
- client: confs.dbFlavor,
- useNullAsDefault: true,
- connection,
- },
- },
- production: {
- migrateOnStart: false,
- },
- },
- },
- ],
- },
- })
|