|
1 | | -const pmx = require('pmx'); |
| 1 | +const { createAndInitServer } = require('./create-server'); |
2 | 2 |
|
3 | | -let pmxProbe; |
4 | | -if (require.main === module && process.env.NODE_ENV === 'production') { |
5 | | - pmxProbe = pmx.init({ |
6 | | - http: true, |
7 | | - errors: true, |
8 | | - custom_probes: true, // Auto expose JS Loop Latency and HTTP req/s as custom metrics |
9 | | - network: true, // Network monitoring at the application level |
10 | | - ports: true, // Shows which ports your app is listening on (default: false) |
11 | | - }); |
12 | | -} |
13 | | - |
14 | | -const Glue = require('glue'); |
15 | | -const config = require('config'); |
16 | | - |
17 | | -const globalRoutes = require('./global-routes'); |
18 | | - |
19 | | -const manifest = { |
20 | | - server: { |
21 | | - cache: config.server.cache, |
22 | | - }, |
23 | | - registrations: [{ |
24 | | - plugin: { |
25 | | - register: 'good', |
26 | | - options: config.logs, |
27 | | - }, |
28 | | - }, { |
29 | | - plugin: 'hapi-auth-cookie', |
30 | | - }, { |
31 | | - plugin: 'hapi-auth-basic', |
32 | | - }, { |
33 | | - plugin: 'hapi-auth-bearer-token', |
34 | | - }, { |
35 | | - plugin: { |
36 | | - register: 'crumb', |
37 | | - options: config.csrf, |
38 | | - }, |
39 | | - }, { |
40 | | - plugin: 'vision', |
41 | | - }, { |
42 | | - plugin: 'inert', |
43 | | - }, { |
44 | | - plugin: { |
45 | | - register: './mongodb', |
46 | | - options: config.mongodb, |
47 | | - }, |
48 | | - }, { |
49 | | - plugin: { |
50 | | - register: './mailjet', |
51 | | - options: config.mailjet, |
52 | | - }, |
53 | | - }, { |
54 | | - plugin: './users', |
55 | | - }, { |
56 | | - plugin: { |
57 | | - register: './login', |
58 | | - options: config.login, |
59 | | - }, |
60 | | - }, { |
61 | | - plugin: { |
62 | | - register: './oauth', |
63 | | - options: config.oauth, |
64 | | - }, |
65 | | - }, { |
66 | | - plugin: './dashboard', |
67 | | - }, { |
68 | | - plugin: { |
69 | | - register: './tasks', |
70 | | - options: config.kue, |
71 | | - }, |
72 | | - }], |
73 | | - connections: [{ |
74 | | - host: config.host.hostname, |
75 | | - port: config.host.port, |
76 | | - routes: { |
77 | | - cors: { |
78 | | - origin: ['*'], |
79 | | - }, |
80 | | - }, |
81 | | - }], |
82 | | -}; |
83 | | - |
84 | | -function createServer() { |
85 | | - return Glue.compose(manifest, { |
86 | | - relativeTo: __dirname, |
87 | | - }); |
88 | | -} |
89 | | - |
90 | | -module.exports = createServer; |
91 | | - |
92 | | -if (require.main === module) { |
93 | | - createServer() |
94 | | - .then(server => server.start().then(() => server)) |
95 | | - .then((server) => { |
96 | | - server.log('info', `Server started on port ${server.connections[0].info.uri}`); |
97 | | - |
98 | | - server.route(globalRoutes); |
99 | | - |
100 | | - // Handle uncaught promise rejections |
101 | | - process.on('unhandledRejection', (reason) => { |
102 | | - server.log('error', `Unhandled rejection: ${reason.stack}`); |
103 | | - }); |
104 | | - |
105 | | - // Error probing |
106 | | - if (pmxProbe) { |
107 | | - server.on('log', (event, { error }) => { |
108 | | - if (error) { |
109 | | - pmxProbe.notify(event.data); |
110 | | - } |
111 | | - }); |
112 | | - } |
113 | | - }) |
114 | | - .catch((err) => { |
115 | | - console.error(err.stack); // eslint-disable-line no-console |
116 | | - process.exit(1); |
117 | | - }); |
118 | | -} |
| 3 | +createAndInitServer(); |
0 commit comments