pm2.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const fs = require('fs')
  2. const path = require('path')
  3. // Yarn may hoist `next` to the repo root, or keep it under apps/next.
  4. const nextBin = [
  5. path.join(__dirname, 'node_modules/next/dist/bin/next'),
  6. path.join(__dirname, '../../node_modules/next/dist/bin/next'),
  7. ].find((candidate) => fs.existsSync(candidate))
  8. if (!nextBin) {
  9. throw new Error('next binary not found in apps/next/node_modules or the repo root node_modules')
  10. }
  11. const argEnvIndex = process.argv.indexOf('--env')
  12. let argEnv = (argEnvIndex !== -1 && process.argv[argEnvIndex + 1]) || ''
  13. const env = {
  14. UNA_API_KEY: process.env.UNA_API_KEY,
  15. UNA_URL: process.env.UNA_URL,
  16. NEXT_PUBLIC_UNA_URL: process.env.NEXT_PUBLIC_UNA_URL,
  17. APP_URL: process.env.APP_URL,
  18. NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
  19. GOOGLE_WEB_CLIENT_ID: process.env.GOOGLE_WEB_CLIENT_ID,
  20. NEXT_PUBLIC_GOOGLE_WEB_CLIENT_ID: process.env.NEXT_PUBLIC_GOOGLE_WEB_CLIENT_ID,
  21. PROTO: process.env.PROTO,
  22. HOST: process.env.HOST,
  23. PORT: process.env.PORT,
  24. HTTPS: process.env.HTTPS,
  25. }
  26. const RUN_ENV_MAP = {
  27. local: {
  28. instances: 2,
  29. max_memory_restart: '250M',
  30. ...env
  31. },
  32. dev: {
  33. instances: 2,
  34. max_memory_restart: '250M',
  35. ...env
  36. },
  37. prod: {
  38. instances: 4,
  39. max_memory_restart: '1000M',
  40. ...env
  41. }
  42. }
  43. if (!(argEnv in RUN_ENV_MAP)) {
  44. argEnv = 'prod'
  45. }
  46. module.exports = {
  47. apps: [
  48. {
  49. name: 'neoapp',
  50. script: nextBin,
  51. args: 'start',
  52. instances: RUN_ENV_MAP[argEnv].instances,
  53. exec_mode: 'cluster',
  54. watch: false,
  55. max_memory_restart: RUN_ENV_MAP[argEnv].max_memory_restart,
  56. env_local: {
  57. APP_ENV: 'local'
  58. },
  59. env_dev: {
  60. APP_ENV: 'dev'
  61. },
  62. env_prod: {
  63. APP_ENV: 'prod'
  64. }
  65. }
  66. ]
  67. }