-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1.14 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
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const session = require('express-session');
const path = require('path');
const authRoutes = require('./routes/authRoutes');
const app = express();
const PORT = process.env.PORT || 3000;
mongoose.connect('mongodb://127.0.0.1:27017/restaurantDB', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(session({ secret: 'your-secret-key', resave: true, saveUninitialized: true }));
// Pass 'app' to authRoutes
app.use('/', authRoutes(app));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'login.html'));
});
app.get('/signup', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'signup.html'));
});
// ... (existing code)
app.get('/dashboard', (req, res) => {
if (!req.session.userId) {
res.redirect('/login');
} else {
res.sendFile(path.join(__dirname, 'views', 'dashboard.html'));
}
});
// ... (existing code)
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});