forked from plone/volto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-server.js
53 lines (45 loc) · 1.59 KB
/
start-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint no-console: 0 */
import dns from 'dns';
import http from 'http';
import app from './server';
import debug from 'debug';
export default function server() {
// If DNS returns both ipv4 and ipv6 addresses, prefer ipv4
dns.setDefaultResultOrder('ipv4first');
const server = http.createServer(app);
// const host = process.env.HOST || 'localhost';
const port = process.env.PORT || 3000;
const bind_address = process.env.RAZZLE_BIND_ADDRESS || '0.0.0.0';
let currentApp = app;
server
.listen(port, bind_address, () => {
if (app.apiPath === app.publicURL || !app.apiPath) {
console.log(`Volto is running in SEAMLESS mode`);
} else {
console.log(`API server (API_PATH) is set to: ${app.apiPath}`);
}
if (app.devProxyToApiPath)
console.log(
`Proxying API requests from ${app.publicURL}/++api++ to ${
app.devProxyToApiPath
}${app.proxyRewriteTarget || ''}`,
);
console.log(`🎭 Volto started at ${bind_address}:${port} 🚀`);
if (!process.env.RAZZLE_PUBLIC_URL)
debug('config')(`Current public URL: ${app.publicURL}`);
})
.on('error', (e) => {
console.error(e.message);
throw e;
});
return () => {
console.log('✅ Server-side HMR Enabled!');
module.hot.accept('./server', () => {
console.log('🔁 HMR Reloading `./server`...');
server.removeListener('request', currentApp);
const newApp = require('./server').default; // eslint-disable-line global-require
server.on('request', newApp);
currentApp = newApp;
});
};
}