-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
37 lines (31 loc) · 967 Bytes
/
app.js
File metadata and controls
37 lines (31 loc) · 967 Bytes
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 express from "express";
import configRoutes from "./routes/index.js";
import dotenv from "dotenv"; // Import dotenv to load environment variables
import session from "express-session";
const app = express();
dotenv.config(); // Loads the variables from .env file
const rewriteUnsupportedBrowserMethods = (req, res, next) => {
if (req.body && req.body._method) {
req.method = req.body._method;
delete req.body._method;
}
next();
};
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(rewriteUnsupportedBrowserMethods);
app.use("/public", express.static("public"));
app.use(
session({
name: "AuthenticationState",
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
})
);
app.set("view engine", "ejs");
configRoutes(app);
app.listen(5000, () => {
console.log("We've now got a server!");
console.log("Your routes will be running on http://localhost:5000");
});