-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (30 loc) · 1.27 KB
/
app.js
File metadata and controls
37 lines (30 loc) · 1.27 KB
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
//Import Libraries
const express = require("express");
const bodyParser = require("body-parser");
const cookies = require("cookie-parser") //helps to get cookies from req and parse them
require('dotenv').config()
//create an app reference to express()
function makeApp(database) {
const app = express();
// Mount middelware
app.use(bodyParser.urlencoded({ extended: true })) //let express know that we want to parse the bodies drom post requests
app.use(cookies()) //let express know we want to use the cookie parser library
app.use(express.json()); //needed to read json data
require("./routes/main")(app, database); //let express know where the route file is
app.set("views", __dirname + "/views"); //set the views directory
app.set("view enging", "ejs"); // set the view engine to EJS
app.engine("html", require("ejs").renderFile); // Set the HTML rednering enginge for EJS
app.use('/static', express.static('static'))
//http redirect
app.use((req, res, next) => {
if (req.secure) {
next();
} else {
console.log("test");
const redirectUrl = 'https://' + req.headers.host + req.url;
res.redirect(301, redirectUrl);
}
});
return app
}
module.exports = { makeApp }