-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
worker.js
40 lines (32 loc) · 1.03 KB
/
worker.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
import SCWorker from "socketcluster/scworker";
import express from "express";
import bodyParser from "body-parser";
import serveStatic from "serve-static";
import path from "path";
import morgan from "morgan";
import healthChecker from "sc-framework-health-check";
import exchange from "./src";
class Worker extends SCWorker {
run() {
console.log(' >> Worker PID:', process.pid);
let environment = this.options.environment;
let app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
let httpServer = this.httpServer;
let scServer = this.scServer;
if (environment === 'development') {
// Log every HTTP request. See https://github.com/expressjs/morgan for other
// available formats.
app.use(morgan('development'));
}
app.use(serveStatic(path.resolve(__dirname, 'public')));
// Add GET /health-check express route
healthChecker.attach(this, app);
httpServer.on('request', app);
exchange(this);
}
}
new Worker();