-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (27 loc) · 916 Bytes
/
server.js
File metadata and controls
35 lines (27 loc) · 916 Bytes
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
const express = require('express');
const app = express();
app.listen(8080);
//no need to manually create the http server with server.createServer, simply get the webpages!
app.get('/', (req,res)=>{
console.log(req.url, req.method);
//the relative path, and to what it is relative to
res.sendFile('./views/index.html', {root: __dirname});
});
app.get('/about', (req,res) =>{
console.log(req.url, req.method);
res.sendFile('./views/about.html', {root: __dirname});
});
app.get('/contact-me', (req,res) =>{
console.log(req.url, req.method);
res.sendFile('./views/contact-me.html', {root: __dirname});
});
//express redirects
app.get('/contact', (req,res) =>{
console.log(req.url, req.method);
res.redirect('/contact-me');
});
//404 - middleware
app.use((req,res)=>{
console.log(req.url, req.method);
res.status(404).sendFile('./views/404.html', {root:__dirname});
})