forked from zaycation/Basic-Express-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (25 loc) · 968 Bytes
/
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
const express = require("express");
const morgan = require("morgan");
const campsiteRouter = require("./routes/campsiteRouter");
const promotionRouter = require("./routes/promotionRouter");
const partnerRouter = require("./routes/partnerRouter");
const hostname = "localhost";
const port = 3000;
const app = express();
app.use(morgan("dev"));
app.use(express.json());
app.use("/campsites", campsiteRouter);
app.use("/campsites/:campsiteId", campsiteRouter);
app.use("/promotions", promotionRouter);
app.use("/promotions/:promotionId", promotionRouter);
app.use("/partners", partnerRouter);
app.use("/partners/:partnerId", partnerRouter);
app.use(express.static(__dirname + "/public"));
app.use((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
res.end("<html><body><h1>This is an Express Server</h1></body></html>");
});
app.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});