-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
88 lines (67 loc) · 2.06 KB
/
server.js
File metadata and controls
88 lines (67 loc) · 2.06 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import express from "express";
import dotenv from "dotenv";
import connectDB from "./config/db.js"
import path from 'path'
import { fileURLToPath } from "url";
import userRouter from "./routes/user.routes.js"
import adminRouter from './routes/admin.route.js'
import session from "express-session";
import MongoStore from "connect-mongo";
import nocache from "nocache";
import middleware from './middlewares/middleware.js'
import flash from 'connect-flash'
import morgan from "morgan";
//* config
dotenv.config()
const app = express();
const PORT = process.env.PORT || 5000
app.use(middleware.nocacheMiddleWare)
// app.use(nocache())
// * getting Dirname
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.use(flash())
app.use(session({
secret : process.env.SESSION_SECRET,
resave :false,
saveUninitialized : false,
store : new MongoStore({
collectionName : 'session',
mongoUrl : process.env.MONGO_URI,
ttl : 1 * 24 * 60 * 60,
autoRemove : "native"
}) ,
// cookie : {secure : true}
}))
// const fs = require('fs')/;
// const path = require('path');
// import fs from 'fs'
// app.get('/stream', (req, res) => {
// const filePath = path.join(__dirname, 'text.txt');
// const stat = fs.statSync(filePath);
// const fileSize = stat.size;
// console.log(stat)
// res.writeHead(200, {
// 'Content-Type': 'application/octet-stream',
// 'Content-Length': fileSize,
// 'Content-Disposition': 'attachment; filename="largefile.zip"'
// });
// const readStream = fs.createReadStream(filePath);
// readStream.pipe(res);
// });
//* styles
app.use('/assets',express.static(__dirname + '/static'))
app.set('view engine', 'ejs')
app.use((req, res ,next)=>{
res.locals.w = req.flash('error')
next()
})
app.use(morgan('dev'))
app.use('/',userRouter) //userRouter
app.use('/admin',adminRouter) //adminRouter
app.listen(PORT , ()=>{
connectDB()
console.log(`listening to the port ${PORT}`)
})