-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
36 lines (30 loc) · 904 Bytes
/
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
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);
const next = require('next');
const gameIO = require('./socketGameController');
const dev = process.env.NODE_ENV !== 'production';
const nextApp = next({ dev });
const nextHandler = nextApp.getRequestHandler();
io.on('connection', socket => {
console.log('socket.io connected');
gameIO.connection(io, socket);
});
gameIO.handlePokemonNoCatch(io);
gameIO.handleOldSessions(io);
app.use('/public', express.static(`${__dirname}/public`));
nextApp.prepare()
.then(() => {
app.get('*', (req, res) => {
return nextHandler(req, res);
});
server.listen(3000, (err) => {
if (err) throw err;
console.log('> Ready on http://localhost:3000')
});
})
.catch((ex) => {
console.error(ex.stack);
process.exit(1);
});