Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

manifest.js 3.3KB

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