-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (36 loc) · 1.25 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
const express = require('express');
const dotenv = require('dotenv');
const connectDB = require('./config/db');
const authRoutes = require('./routes/authRoutes');
const commentRoutes = require('./routes/commentRoutes');
const userRoutes = require('./routes/userRoutes');
const messageRoutes = require('./routes/messageRoutes');
const bodyParser = require('body-parser');
const path = require('path');
const session = require('express-session');
dotenv.config();
connectDB();
const app = express();
app.use(bodyParser.json());
// Use the secret key from the environment variable
const sessionSecret = process.env.SESSION_SECRET;
app.use(session({
secret: sessionSecret,
resave: false,
saveUninitialized: true,
cookie: { secure: false } // Set to true if using HTTPS
}));
// Serve static files
app.use(express.static(path.join(__dirname, 'public')));
// Define the route for the homepage
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, './public/login.html'));
});
app.use('/api/auth', authRoutes);
app.use('/api/comments', commentRoutes);
app.use('/api/users', userRoutes);
app.use('/api/messages', messageRoutes);
const PORT = process.env.PORT || 3000;
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server running on port ${PORT}`);
});