-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (30 loc) · 1.07 KB
/
app.js
File metadata and controls
51 lines (30 loc) · 1.07 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "public")));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
mongoose
.connect(process.env.MONGODB_URI)
.then(() => console.log("MongoDB connected successfully"))
.catch((err) => console.log("MongoDB connection error:", err));
const adminRoutes = require("./routes/admin");
const apiRoutes = require("./routes/api");
app.use("/admin", adminRoutes);
app.use("/api", apiRoutes);
app.get("/", (req, res) => {
res.redirect("/admin");
});
app.get("/test-css", (req, res) => {
res.send(`
<h1>CSS Test</h1>
<link rel="stylesheet" href="/styles.css">
<p>If the background turns yellow, your CSS is loading!</p>
`);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));