-
Notifications
You must be signed in to change notification settings - Fork 51
/
server.js
executable file
·42 lines (32 loc) · 993 Bytes
/
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
#!/usr/bin/env node
const http = require('http');
const app = require('./index');
const { wss } = require('./websocket');
const config = require('./config/index');
if (config.startWithStudio) {
(async () => {
const { handler: soulStudioHandler } = await import(
'soul-studio/build/handler.js'
);
app.use('/studio', soulStudioHandler);
})();
}
const server = http.createServer(app);
const port = config.port;
const baseURL = `http://localhost:${port}`;
const coreURL = `${baseURL}/api/`;
const studioURL = `${baseURL}/studio/`;
server.listen(port, () => {
console.log(`Soul is running...`);
console.log(` > Core API at ${coreURL}`);
if (config.startWithStudio) {
console.log(` > Studio at ${studioURL}`);
require('child_process').exec(`open ${studioURL}`);
}
});
server.on('upgrade', (request, socket, head) => {
wss.handleUpgrade(request, socket, head, (socket) => {
wss.emit('connection', socket, request);
});
});
module.exports = {};