Showing
2 changed files
with
24 additions
and
1 deletions
... | @@ -2,7 +2,9 @@ const fs = require('fs'); | ... | @@ -2,7 +2,9 @@ const fs = require('fs'); |
2 | const path = require('path'); | 2 | const path = require('path'); |
3 | const express = require('express'); | 3 | const express = require('express'); |
4 | const exphbs = require('express-handlebars'); | 4 | const exphbs = require('express-handlebars'); |
5 | +const http = require('http'); | ||
5 | const app = require('./server'); | 6 | const app = require('./server'); |
7 | +const socket = require('./socket'); | ||
6 | 8 | ||
7 | const hbs = exphbs.create({ | 9 | const hbs = exphbs.create({ |
8 | helpers: { | 10 | helpers: { |
... | @@ -26,4 +28,9 @@ fs.readdirSync(path.resolve(__dirname, 'routes')).forEach((name) => { | ... | @@ -26,4 +28,9 @@ fs.readdirSync(path.resolve(__dirname, 'routes')).forEach((name) => { |
26 | 28 | ||
27 | app.use(express.static(path.resolve(__dirname, 'public'))); | 29 | app.use(express.static(path.resolve(__dirname, 'public'))); |
28 | 30 | ||
29 | -app.listen(3429); | 31 | +let server = http.createServer(app); |
32 | +socket.init(http); | ||
33 | + | ||
34 | +server.listen(3429, () => { | ||
35 | + console.log('Listening on port 3429'); | ||
36 | +}); | ... | ... |
src/socket.js
0 → 100644
1 | +const sio = require('socket.io'); | ||
2 | +const db = require('./db'); | ||
3 | + | ||
4 | +let io; | ||
5 | +module.exports = { | ||
6 | + init(http) { | ||
7 | + io = sio(http); | ||
8 | + io.on('connection', (socket) => { | ||
9 | + socket.on('init', (id) => { | ||
10 | + db.get('subthread').find({parent: id}, {sort: '+_id'}).each((thread, _) => { | ||
11 | + socket.emit('thread', thread); | ||
12 | + }); | ||
13 | + }); | ||
14 | + }); | ||
15 | + } | ||
16 | +}; |
-
Please register or login to post a comment