-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20-sever-style.js
More file actions
51 lines (47 loc) · 1.48 KB
/
Copy path20-sever-style.js
File metadata and controls
51 lines (47 loc) · 1.48 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
const http = require('http');
const {readFileSync} = require('fs')
//get all files
const homePage = readFileSync('./node-express-course/02-express-tutorial/navbar-app/index.html')
const homeStyle = readFileSync('./node-express-course/02-express-tutorial/navbar-app/styles.css')
const homeImage = readFileSync('./node-express-course/02-express-tutorial/navbar-app/logo.svg')
const homeLogic = readFileSync('./node-express-course/02-express-tutorial/navbar-app/browser-app.js')
const server = http.createServer((req,res)=>{
const url = req.url;
// home page
if(url === '/'){
res.writeHead(200,{'content-type':'text/html'})
res.write(homePage)
res.end()
}
//about page
else if(url === '/about'){
res.writeHead(200,{'content-type':'text/html'})
res.write('<h1>about page</h1>')
res.end()
}
//styles
else if(url === '/styles.css'){
res.writeHead(200,{'content-type':'text/css'})
res.write(homeStyle)
res.end()
}
//image/logo
else if(url === '/logo.svg'){
res.writeHead(200,{'content-type':'image/svg+xml'})
res.write(homeImage)
res.end()
}
//logic
else if(url === '/browser-app.js'){
res.writeHead(200,{'content-type':'text/javascript'})
res.write(homeLogic)
res.end()
}
//404
else{
res.writeHead(404,{'content-type':'text/html'})
res.write('<h1>error 404</h1>')
res.end()
}
})
server.listen(5003)