-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (46 loc) · 1.34 KB
/
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
54
55
56
57
58
const express = require('express');
const http = require('http');
const nocache = require('nocache');
const compression = require('compression');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
app.disable('x-powered-by');
const port = process.env.PORT || 3000;
app.use(compression());
app.use(/\/((?!js).)*/, nocache());
app.use("/headers/Authorization", function (req, res, next) {
if (req.headers['authorization'] === 'Basic SGVsbG8gV29ybGQ=') {
res.sendStatus(200);
} else {
res.sendStatus(406);
}
});
app.use("/headers/:header", function (req, res, next) {
const { params: { header = '' } } = req;
if (req.headers[header.toLowerCase()]) {
res.sendStatus(200)
} else {
res.sendStatus(404)
}
});
app.use("/method", function (req, res, next) {
res.sendStatus(200);
});
app.use("/protocol", function (req, res, next) {
res.sendStatus(200);
});
const WebSocket = require('ws');
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
app.use(express.static(path.join(__dirname, 'dist')));
wss.on('connection', function(ws, req) {
console.log('socket connected');
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('connected');
});
server.listen(port, () => {
console.log('Listening on %d', port);
});