-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (48 loc) · 1.66 KB
/
server.js
File metadata and controls
60 lines (48 loc) · 1.66 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
const express = require("express");
const cookieParser = require("cookie-parser");
const path = require("path");
const dotenv = require("dotenv");
const authRouter = require("./routes/auth.routes");
const db = require("./utils/database");
dotenv.config({ path: ".env.local" });
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
// Serve static files (css, js, images, etc.)
app.use(express.static(path.join(__dirname,'src')));
app.use(express.static(path.join(__dirname,'assets')));
app.use(express.static(path.join(__dirname,'images')));
app.use(express.static(path.join(__dirname,'public')));
app.use(express.static(path.join(__dirname)));
// Serve index.html at root
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "src","index.html"));
});
// Serve login page from src/pages directory
app.get("/login", (req, res) => {
res.sendFile(path.join(__dirname, "src/pages/login.html"));
});
// Serve signup page from src/pages directory
app.get("/signup", (req, res) => {
res.sendFile(path.join(__dirname, "src/pages/login.html"));
});
// Serve Rent Your Car page
app.get("/rent-your-car", (req, res) => {
res.sendFile(path.join(__dirname, "rentcar.html"));
});
app.use("/", authRouter);
// Handle 404 - Must be after all other routes
app.use((req, res, next) => {
res.status(404).sendFile(path.join(__dirname, '404.html'));
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
db();
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});