-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
56 lines (50 loc) · 1.45 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-disable no-unused-vars */
const express = require('express');
const app = express();
const session = require('express-session');
const passport = require('passport');
const ejs = require('ejs');
const helmet = require('helmet');
const dotenv = require('dotenv').config();
const indexRouter = require('./routes');
const authRouter = require('./routes/auth');
const mypageRouter = require('./routes/mypage');
const createRouter = require('./routes/create');
const groupRouter = require('./routes/group');
const dbConfig = require('./config/database');
const PORT = 3000;
app.set('view engine', 'ejs');
app.use(express.text());
app.use(express.json());
app.use(helmet());
app.use(express.static(__dirname));
app.use(express.urlencoded({ extended: false }));
app.use(
session({
secret: process.env.SESSION_SECRET,
store: dbConfig.db,
resave: false,
saveUninitialized: false
})
);
app.use(passport.initialize());
app.use(passport.session());
// Routers
app.use('/', indexRouter);
app.use('/auth', authRouter);
app.use('/mypage', mypageRouter);
app.use('/create', createRouter);
app.use('/group', groupRouter);
// 404 responses handler
app.use((req, res, next) => {
res.status(404).send("Sorry can't find that!");
});
// Server error handler
app.use((err, req, res, next) => {
// console.error(err.stack);
res.status(500).send('Something broke!');
});
// Start HTTP server listening
app.listen(PORT, () => {
console.log(`listening on ${PORT}`);
});