-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
56 lines (44 loc) · 1.27 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
const express = require("express");
const bodyParser = require("body-parser");
const session = require('express-session')
const app = express();
const {run} = require("./db")
run().catch(console.dir)
const path = require("path");
const authRoutes = require("./routes/auth");
const productsRoutes = require("./routes/products");
const apiRoutes = require("./routes/api");
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "public")));
console.log(process.env.SECRET);
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: false
}));
app.use((req, res, next) => {
res.set({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'DELETE,GET,PATCH,POST,PUT',
'Access-Control-Allow-Headers': 'Content-Type,Authorization'
});
if(req.method === 'OPTIONS') {
res.send(200);
} else {
next();
}
})
app.set("view engine", "ejs");
app.set("views", "views");
app.use((req, res, next) => {
console.log(req.url);
next();
});
app.use("/auth", authRoutes);
app.use("/product", productsRoutes);
app.use("/api", apiRoutes)
app.use("/", (req, res) => {
res.render("home", {user: "Ishaq"});
});
app.listen(5000);