-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
69 lines (53 loc) · 1.62 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
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require('mongoose');
const session = require('express-session');
const passport = require('passport');
const cookieParser = require("cookie-parser");
// Routers
const indexRouter = require("./routes/index");
const authRouter = require("./routes/auth");
const adminRouter = require("./routes/admin");
const petsRouter = require("./routes/pets");
const iListRouter = require("./routes/ilist");
const requestRouter = require("./routes/request");
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.use(cookieParser());
app.enable('trust proxy'); // add this line
app.use(session({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true,
proxy: true, // add this line
cookie: {
secure: true,
maxAge: 3600000,
}
}));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect(process.env.DATABASE_URL, {useNewUrlParser: true, useUnifiedTopology: true});
mongoose.set("useCreateIndex", true);
// Using Routes
app.use("/", indexRouter);
app.use("/auth", authRouter);
app.use("/admin", adminRouter);
app.use("/pets", petsRouter);
app.use("/IList", iListRouter);
app.use("/request", requestRouter);
app.use(function(req, res, next) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('404', { url: req.url });
return;
}
});
app.listen(process.env.PORT || 3000, () => {
console.log("Server is running");
});