forked from ironhack-labs/lab-express-basic-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (37 loc) · 1.24 KB
/
app.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
// 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
// Here you should create your Express app:
const app = express();
// MIDDLEWARE
// Here you should set up the required middleware:
// - `express.static()` to serve static files from the `public` folder
// - `express.json()` to parse incoming requests with JSON payloads
// - `morgan` logger to log all incoming requests
app.use(express.static('public'))
app.use(express.json());
app.use(morgan('dev'));
// ROUTES
// Start defining your routes here:
app.get('/', (request, response) => {
response.sendFile(__dirname + '/views/home.html')
})
app.get('/blog', (req, res) => {
res.sendFile(__dirname + '/views/blog.html')
})
app.get('/api/projects', (req, res) => {
res.sendFile(__dirname + '/data/projects.json')
})
app.get('/api/articles', (req, res) => {
res.sendFile(__dirname + '/data/articles.json')
})
app.get('/*', (req, res) => {
res.sendFile(__dirname + '/views/not-found.html')
})
// START THE SERVER
// Make your Express server listen on port 5005:
app.listen(5005, () => {
console.log("server running in port 5005");
});