-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (48 loc) · 1.48 KB
/
app.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
const express = require("express");
const app = express();
const http = require('http');
const server = http.createServer(app);
const session = require("express-session");
const FileStore = require("session-file-store")(session);
const bodyParser = require("body-parser");
const init = require("./init.js");
const indexRouter = require("./routes/index.js");
const accountRouter = require("./routes/account.js");
const boardRouter = require("./routes/board.js");
const searchRouter = require("./routes/search.js");
const adminRouter = require("./routes/admin.js");
const helmet = require("helmet");
// socket -> chating
const { Server } = require('socket.io');
const io = new Server(server);
io.on('connection',function(socket){
socket.on('enter', (msg) => {
io.emit('enter', msg);
});
socket.on('message', (msg) => {
io.emit('message', msg);
});
})
app.use(express.static("public"));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session({
secret: 'iwanttogotothemoon',
resave: false,
saveUninitialized: true,
store: new FileStore({
logFn: function(){}
})
}))
app.use("/", indexRouter);
app.use("/account", accountRouter);
app.use("/board",boardRouter);
app.use("/search",searchRouter);
app.use("/admin",adminRouter);
app.get('*', (req, res) => {
res.redirect('/')
})
app.use(helmet());
server.listen(init.connect.port, init.connect.hostname, function(){
console.log("Server running at 3000");
})