This repository has been archived by the owner on Feb 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
98 lines (73 loc) · 2.29 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs').__express;
const flash = require('connect-flash');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const passport = require('passport');
const cors = require('cors');
const methodOverride = require('method-override');
require('./config/passport');
const app = express();
//const app = polka();
require('express-helpers')(app);
// view engine setup
//app.disable('etag');
//app.set('views', path.join(__dirname, 'views'));
app.set("views", "./views");
//app.set("views", "./public/dist/");
app.set('view engine', 'ejs');
app.engine('.ejs', ejs); //
app.locals.rmWhitespace = true;
// Routes
const episodes = require('./routes/episodes');
const series = require('./routes/series');
app.locals.moment = require('moment');
const moment = require('moment');
moment.locale('es');
//app.use(express.logger('dev'));
//app.use(logger('dev'));
app.use(cors());
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({ extended: false }));
// Angular DIST output folder
//app.use(express.static(path.join(__dirname, 'dist')));
// Original no angular
app.use(express.static(path.join(__dirname, 'public')));
app.use(logger('dev'));
app.use(methodOverride('_method'));
//login system
app.use(cookieParser());
app.use(session({
cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 },
secret: 'kontol',
saveUninitialized: false,
resave: false
}));
app.use(passport.initialize());
app.use(passport.session());
// Middlewares
app.use(flash());
app.use((req, res, next) => {
res.locals.success_messages = req.flash('success');
res.locals.error_messages = req.flash('error');
res.locals.isAuthenticated = req.user ? true : false;
next();
});
// Routes
app.use('/series', series);
app.use('/', episodes);
app.use('/episodes', episodes);
app.use('/show', episodes);
app.use('/anime', series);
app.use('/episodes', series);
app.use('/users', require('./routes/users'));
// Catach 404 Errors and forward them to error handler
app.use(function (req, res, next) {
var err = new Error('404: Not Found ' + req.originalUrl); //here
err.status = 404;
next(err);// or null
});
module.exports = app;