You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

manifest.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. require('dotenv').config()
  2. const Confidence = require('@hapipal/confidence')
  3. const Inert = require('@hapi/inert')
  4. const Vision = require('@hapi/vision')
  5. const Schwifty = require('@hapipal/schwifty')
  6. const HapiSwagger = require('hapi-swagger')
  7. const confs = {
  8. local: {
  9. db: process.env.DB_NAME,
  10. host: process.env.DB_HOST,
  11. port: process.env.DB_PORT,
  12. ssl: false,
  13. user: process.env.DB_USER,
  14. pw: process.env.DB_ROOT_PASSWORD,
  15. },
  16. prod: {
  17. db: process.env.PSCALE_DB_NAME,
  18. host: process.env.PSCALE_DB_HOST,
  19. port: process.env.PSCALE_DB_PORT,
  20. branch: process.env.PSCALE_DB_BRANCH,
  21. ssl: true,
  22. user: process.env.PSCALE_DB_USER,
  23. pw: process.env.PSCALE_DB_PASSWORD,
  24. },
  25. dbFlavor: process.env.DB_TYPE,
  26. useLocalDb: () => {
  27. return process.env.USE_LOCAL_DB == 'true'
  28. },
  29. }
  30. const _current = {
  31. ssl: confs.useLocalDb() ? confs.local.ssl : confs.prod.ssl,
  32. host: confs.useLocalDb() ? confs.local.host : confs.prod.host,
  33. port: confs.useLocalDb() ? confs.local.port : confs.prod.port,
  34. database: confs.useLocalDb() ? confs.local.db : confs.prod.db,
  35. user: confs.useLocalDb() ? confs.local.user : confs.prod.user,
  36. password: confs.useLocalDb() ? confs.local.pw : confs.prod.pw,
  37. }
  38. /** Glue manifest as a confidence store */
  39. module.exports = new Confidence.Store({
  40. server: {
  41. host: process.env.API_HOST,
  42. port: {
  43. $filter: 'NODE_ENV',
  44. $default: {
  45. $param: 'API_PORT',
  46. $coerce: 'number',
  47. $default: process.env.API_PORT,
  48. },
  49. test: { $value: undefined }, // Let the server find an open port
  50. },
  51. debug: {
  52. $filter: 'NODE_ENV',
  53. $default: {
  54. log: ['error', 'start'],
  55. request: ['error'],
  56. },
  57. production: {
  58. request: ['implementation'],
  59. },
  60. },
  61. },
  62. register: {
  63. plugins: [
  64. /** Main app */
  65. {
  66. plugin: '../lib',
  67. routes: {
  68. prefix: '/api',
  69. },
  70. options: {
  71. jwtKey: {
  72. $filter: 'NODE_ENV',
  73. $default: {
  74. $param: 'APP_SECRET',
  75. $default: 'app-secret',
  76. },
  77. // Use .env file in production
  78. production: {
  79. $param: 'APP_SECRET',
  80. },
  81. },
  82. },
  83. },
  84. /** Documentaion plugins */
  85. Inert,
  86. Vision,
  87. {
  88. plugin: HapiSwagger,
  89. options: {
  90. info: { title: 'Test API Documentation' },
  91. },
  92. },
  93. /** Model and knex integration */
  94. {
  95. plugin: Schwifty,
  96. options: {
  97. $filter: 'NODE_ENV',
  98. $default: {},
  99. $base: {
  100. migrateOnStart: true,
  101. knex: {
  102. client: confs.dbFlavor,
  103. useNullAsDefault: true,
  104. connection: {
  105. database: _current.database,
  106. host: _current.host,
  107. port: _current.port,
  108. ssl: _current.ssl,
  109. user: _current.user,
  110. password: _current.password,
  111. },
  112. },
  113. },
  114. production: {
  115. migrateOnStart: false,
  116. },
  117. },
  118. },
  119. ],
  120. },
  121. })