-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
62 lines (48 loc) · 1.59 KB
/
server.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
const express = require("express")
const app = express()
const methodOverride = require('./middlewares/method_override')
const port = process.env.PORT || 8080
const session = require("express-session")
const itemController = require('./controllers/item_controller')
const sessionController = require('./controllers/session_controller')
const userController = require('./controllers/user_controller')
const orderController = require('./controllers/order_controller')
const setCurrentUser = require('./middlewares/set_currentUser')
const viewHelpers = require("./middlewares/view_helpers")
const viewHelpers1 = require("./middlewares/view_helpers1")
const MemoryStore = require("memorystore")(session)
const { Pool } = require("pg")
const config = {
dev: {
database: "onlinestore",
},
prod: {
connectionString: process.env.DATABASE_URL,
},
}
module.exports = new Pool(process.env.DATABASE_URL ? config.prod : config.dev)
app.set("view engine", "ejs")
app.use(express.static("public"))
app.use(express.urlencoded({extended: true}))
app.use(methodOverride)
app.use(
session({
cookie: { maxAge: 86400000 },
store: new MemoryStore({
checkPeriod: 86400000, // prune expired entries every 24h
}),
secret: process.env.SESSION_SECRET || "mistyrose",
resave: false,
saveUninitialized: true,
})
)
app.use(setCurrentUser)
app.use(viewHelpers)
app.use(viewHelpers1)
app.use(sessionController)
app.use(userController)
app.use(itemController)
app.use(orderController)
app.listen(port, () =>{
console.log(`listening on port ${port}`)
})