Video 45: Serving up Static Assets
This commit is contained in:
parent
2a8bb440df
commit
8f136ffed8
8
web-server/public/about.html
Normal file
8
web-server/public/about.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>About</h1>
|
||||
</body>
|
||||
</html>
|
8
web-server/public/help.html
Normal file
8
web-server/public/help.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Help</h1>
|
||||
</body>
|
||||
</html>
|
8
web-server/public/index.html
Normal file
8
web-server/public/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>From a static file</h1>
|
||||
</body>
|
||||
</html>
|
@ -1,27 +1,15 @@
|
||||
const path = require('path')
|
||||
const express = require('express')
|
||||
|
||||
const app = express()
|
||||
const publicDirectoryPath = path.join(__dirname, '../public')
|
||||
|
||||
app.get('', (req, res) => {
|
||||
res.send('<h1>Weather</h1>')
|
||||
})
|
||||
|
||||
app.get('/help', (req, res) => {
|
||||
res.send([{
|
||||
name: 'Jason',
|
||||
age: 38
|
||||
}, {
|
||||
name: 'Sarah'
|
||||
}])
|
||||
})
|
||||
|
||||
app.get('/about', (req, res) => {
|
||||
res.send('<h1>About</h1>')
|
||||
})
|
||||
app.use(express.static(publicDirectoryPath))
|
||||
|
||||
app.get('/weather', (req, res) => {
|
||||
res.send({
|
||||
location: 'Calgary',
|
||||
forecast: 'It\'s snowing. It\'s really gross out.'
|
||||
forecast: 'It\'s snowing. It\'s really gross out.',
|
||||
location: 'Calgary'
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user