-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (23 loc) · 853 Bytes
/
server.js
File metadata and controls
31 lines (23 loc) · 853 Bytes
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
// Everything that was in the file before goes here
var express = require('express');
app = express();
app.use(express.static('public')) // We will want this later
app.set('view engine', 'ejs')
app.get('/banned-words', function(req, res){
res.render('banned-words', {'wordlist': ""})
})
app.get('/', function(req, res){
res.render('index', {'messages': ""})
})
var port = process.env.PORT || 3000; // For when we deploy to Heroku
var server = app.listen(port)
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
socket.on('setUsername', function (data) {
socket.username = data
})
socket.on('message', function (message) {
var data = { 'message' : message, 'username': socket.username }
socket.broadcast.emit('message', data);
})
})