-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
39 lines (31 loc) · 912 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
37
38
39
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const path = require('path');
var JsonDB = require('node-json-db');
var settingDB = new JsonDB("settings", true, true);
var userDB = new JsonDB("users", true, true);
var userLib = require('./assets/libs/user.js');
app.get('/*', function(req, res){
var url = req.url.split("?")[0];
url = url.replace(/\.\.\//g, "");
if (url === "/") url = "index.html";
var file = path.join(__dirname, "assets/html/", url);
res.sendFile(file);
});
var mime = {
".js": "text/javascript",
".html": "text/html",
".css": "text/css",
".png": "image/png",
".jpg": "image/jpg",
".gif": "image/gif"
};
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});