-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (53 loc) · 1.76 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const app = express();
const server = require('http').createServer(app)
const io = require('socket.io')(server);
const PORT = process.env.PORT || 3000;
const fs = require('fs');
const path = require("path");
app.use(express.static('public'));
app.use(express.static(__dirname + '/node_modules/bootstrap/dist'));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/indexes/index.html');
});
app.get('/directory', (req, res) => {
res.sendFile(__dirname + '/indexes/directory.html');
});
app.get('/chat', (req, res) => {
res.sendFile(__dirname + '/error/common404.html');
});
app.get('/chat/public', (req, res) => {
res.sendFile(__dirname + '/error/common404.html');
});
app.get('/chat/private', (req, res) => {
res.sendFile(__dirname + '/error/common404.html');
});
app.get('/learnmore', (req, res) => {
res.sendFile(__dirname + '/indexes/rules.html');
});
app.get('/chat/public/1', (req, res) => {
res.sendFile(__dirname + '/chat/public/public1.html');
});
app.get('*', function(req, res){
res.status(404).send('404 error!');
res.status(500).send('500 error!');
});
server.listen(PORT, () => {
console.log('Server is running on port: ' + PORT);
});
io.on('connection', (socket) => {
socket.on('disconnect', () => {
io.emit('send message', {message: `${socket.username} has left the chat`, user: "Welcome Bot"});
});
socket.on('new message', (msg) => {
console.log(msg)
io.emit('send message', {message: msg, user: socket.username});
});
socket.on('new user', (usr) => {
socket.username = usr;
io.emit('send message', {message: `${socket.username} has joined the chat`, user:"Welcome Bot"})
});
socket.on('password', (pswd) => {
socket.password = pswd;
});
});