-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (41 loc) · 1.25 KB
/
Copy pathindex.js
File metadata and controls
50 lines (41 loc) · 1.25 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
38
39
40
41
42
43
44
45
46
47
48
49
50
//index.js
//npm install express
//npm install ejs
//npm install express-session
//npm install connect-mongo
import express from 'express'
import path from 'path'
import session from 'express-session'
import MongoStore from 'connect-mongo'
import dotenv from 'dotenv'
dotenv.config()
const app = express()
const port = process.env.PORT || 3000
process.env.TZ = "Asia/Phnom_Penh"
const __dirname = path.resolve()
import settings from './settings.js'
import frontend from './routes/frontend.js'
import backend from './routes/backend.js'
import mydb from './models/mongodb.js'
app.use('/',async function(req,res,next){
req.mydb = await mydb
req.settings = settings
next()
})
app.use(session({
store: MongoStore.create({mongoUrl:process.env.DATABASE_URI}),
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false
}))
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.urlencoded({extended:false}))
app.use(express.json())
app.use('/',frontend)
app.use('/admin',backend)
app.listen(port,function(){
console.log(`This application is listening to the port: ${port}`)
})
export default app