-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (31 loc) · 1.12 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
const express = require('express');
const app = express();
const path = require('path');
const restRouter = require('./routes/rest');
const indexRouter = require('./routes/index');
const mongoose = require('mongoose');
app.use(express.static(path.join(__dirname,'../public/')))
app.use('/',indexRouter);
app.use('/api/v1/',restRouter);
app.use(function(req, res) {
res.sendFile('index.html', {root: path.join(__dirname, '../public')});
});
const http = require('http');
const socketIO = require('socket.io');
const io = socketIO();
const editorSocketService = require('./services/editorSocketService.js')(io);
const server = http.createServer(app);
io.attach(server);
server.listen(process.argv[2]);
server.on('error',onError);
server.on('listening',onListening);
function onError(error){
throw error;
}
function onListening() {
const address = server.address();
// const bind = typeof address == 'string' ? 'pipe ' + address : 'port ' + address.port;
const bind = address.port;
console.log('listening on ' + bind);
}