-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 973 Bytes
/
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
'use strict';
const express = require('express');
const logger = require('morgan');
const bodyParser = require('body-parser');
const cors = require('cors');
const http = require('http');
const path = require('path');
const router = require('./router');
const config = require('./config');
const socket = require('./socket.io');
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(logger('dev'));
app.use('/', router);
/*sadff*/
app.use((req, res, next) => {
let err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
console.log(err);
res.status(err.status || 500);
res.send(err);
});
const server = http.createServer(app);
const io = require('socket.io')(server);
io.on('connect', socket.connect);
server.listen(config.port);
console.log(`server start on port ${config.port}`);