-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
77 lines (47 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require('express');
const db = require('./routes/db-config');
const cookie = require('cookie-parser')
const dotenv = require('dotenv');
const searchRouter = require('./routes/search');
dotenv.config({path:'./.env'});
const fs = require('fs').promises;
const PORT = process.env.PORT|| 5001;
const path = require('path');
const app = express();
const publicDirectory = path.join(__dirname,'./public');
app.use(express.static(publicDirectory));
app.get('/about',(req,res)=>{
res.sendFile(path.join(publicDirectory,"about.html"));
})
app.get("/pdf/:pdfName", (req, res) => {
var requipdf = req.params.pdfName;
const filePath = path.join(__dirname, "uploads", requipdf);
console.log(filePath);
res.sendFile(filePath);
});
app.use(express.urlencoded({extended: false}));
app.set('view engine','hbs');
app.set('views','./views');
app.use(cookie());
app.use(express.json());
// // Endpoint to get the visitor count
app.get('/getVisitorCount', async (req, res) => {
try {
const count = await fs.readFile('./counter.txt', 'utf-8');
res.json({ count: parseInt(count) });
} catch (error) {
console.error('Error fetching visitor count:', error);
res.sendStatus(500);
}
});
// define routes
app.use('/', require('./routes/pages'));
app.use('/search', searchRouter);
app.use('/auth', require('./routes/auth'));
app.use('/auth/dashbord', require('./routes/dashboard'));
app.get('*', (req, res) => {
res.status(404).sendFile(path.join(__dirname, 'public', 'pnf.html'));
});
app.listen(PORT,() =>{
console.log(`Server Started on port ${PORT}`);
})