-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 1.07 KB
/
index.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
const express = require('express')
const app = express()
const cors = require('cors')
const session = require('express-session')
const mongoStore = require('connect-mongo')
require('dotenv').config()
app.use(cors({
origin: ["https://ownxmind.netlify.app", "http://localhost:5173"],
methods: ["GET", "POST"],
credentials: true
}))
const productsRouter = require('./routes/products.js')
const orderRouter = require("./routes/order.js")
const PORT = process.env.PORT || 4000
app.use(express.json())
app.set('trust proxy', 1)
app.use(session({
saveUninitialized: true,
resave: true,
secret: process.env.SESSION_SECRET,
store: mongoStore.create({
mongoUrl: process.env.MONGODB_URI,
dbName: 'ownxmind'
}),
cookie: {
maxAge: 1 * 24 * 60 * 60 * 100,
}
}))
app.get('/', (req, res, next) => {
return res.json({status: 'success', message: 'Session implemented'})
})
app.post('/cart')
app.use ('/products', productsRouter)
app.use ('/order', orderRouter)
app.listen(PORT, () =>{
console.log(`Listening on localhost:${PORT}...`)
})