-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
46 lines (38 loc) · 1.11 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
import express from 'express';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import path from 'path';
import createError from 'http-errors';
import passport from 'passport';
import dotenv from 'dotenv';
import flash from 'connect-flash';
import cors from 'cors';
import bodyParser from 'body-parser';
import connect from './schemas';
import routes from './routes';
import passportConfig from './passport';
const app = express();
connect(); // db 연결
dotenv.config();
passportConfig(passport);
app.use(logger('dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(flash());
app.use(passport.initialize());
app.use(cors());
app.use(routes);
app.use(function(req, res, next) {
next(createError(404));
});
app.use(function(err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.json({
"result":"error"
});
});
module.exports = app;