-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (58 loc) · 1.86 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
58
59
60
61
62
63
const express = require('express');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const { environment, sessionSecret } = require("./config");
const landingRouter = require('./routes/landing');
const moviesRouter = require('./routes/movieTab');
const seriesRouter = require('./routes/seriesTab');
const searchRouter = require('./routes/search');
const originalsRouter = require('./routes/originals');
const accountRouter = require('./routes/account');
const profilesRouter = require('./routes/profiles');
const homeRouter = require('./routes/home');
const videoDetailRouter = require('./routes/video-detail');
const { restoreAccount } = require('./auth');
const app = express();
app.use(express.static('public'))
app.set('view engine', 'pug');
app.use(morgan('dev'));
app.use(cookieParser(sessionSecret));
// app.use(bodyParser());
app.use(session({
name: 'dizney-plus.sid',
secret: sessionSecret,
resave: false,
saveUninitialized: false,
}));
app.use(express.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(restoreAccount);
app.use(accountRouter);
app.use(homeRouter);
app.use(profilesRouter);
app.use(landingRouter)
app.use(moviesRouter)
app.use(seriesRouter)
app.use(originalsRouter)
app.use(searchRouter)
// app.use(whosWatching)
app.use(videoDetailRouter);
app.use((req, res, next) => {
const err = new Error("The requested resource couldn't be found.");
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
const isProduction = environment === "production";
res.json({
title: err.title || "Server Error",
message: err.message,
errers: err.errors,
stack: isProduction ? null : err.stack,
});
});
module.exports = app;