forked from ironhack-labs/lab-express-basic-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (38 loc) · 1.23 KB
/
Copy pathapp.js
File metadata and controls
52 lines (38 loc) · 1.23 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
// IMPORT PACKAGES
// Here you should import the required packages for your Express app: `express` and `morgan`
const express = require("express");
const morgan = require("morgan");
// CREATE EXPRESS APP
const app = express();
// MIDDLEWARE
// Here you should set up the required middleware:
// - `express.static()` to serve static files from the `public` folder
app.use(express.static("public"));
// - `express.json()` to parse incoming requests with JSON payloads
app.use(express.json());
// - `morgan` logger to log all incoming requests
app.use(morgan("dev"));
const projects = require("./data/projects.json");
const articles = require("./data/articles.json");
// ROUTES
// Start defining your routes here:
app.get("/", (req, res) => {
res.sendFile(__dirname + "/view/home.html");
})
app.get("/blog", (req, res) => {
res.sendFile(__dirname + "/view/blog.html");
})
app.get("/api/projects", (req, res) => {
res.json (projects);
})
app.get("/api/articles", (req, res) => {
res.json (articles);
})
app.get("/*", (req, res) => {
res.sendFile(__dirname + "/view/not-found.html");
})
// START THE SERVER
// Make your Express server listen on port 5005:
app.listen(5005, () => {
console.log("Server is listening on port 5005");
})