-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (46 loc) · 1.09 KB
/
index.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
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const api = require(path.join(process.cwd(), 'api', 'main.js'));
const clientList = [{
deviceId: 0,
deviceName: '',
token: '',
login: false,
username: 'admin',
}, ];
const userList = [{
username: 'user',
password: '123456',
socketId: null,
islogin: false,
},
{
username: 'non',
password: '123456',
socketId: null,
islogin: false,
},
];
const app = express();
app.use(
morgan('tiny', {
skip: (req, res) => /static|\.ico/.test(req.originalUrl),
}),
);
app.set('view engine', 'ejs');
const port = process.env.PORT || 80;
const server = app.listen(port);
const io = require('socket.io')(server, {
transports: ['websocket'],
});
app.use('/static', express.static(path.join(process.cwd(), 'asset')));
app.use(
bodyParser.urlencoded({
extended: true,
}),
);
app.use(bodyParser.json());
// setup route
api(app, io, userList, clientList);