1
0

Video 45: Serving up Static Assets

This commit is contained in:
Jason Williams 2019-09-29 18:53:20 -06:00
parent 2a8bb440df
commit 8f136ffed8
4 changed files with 30 additions and 18 deletions

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>About</h1>
</body>
</html>

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Help</h1>
</body>
</html>

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>From a static file</h1>
</body>
</html>

View File

@ -1,27 +1,15 @@
const path = require('path')
const express = require('express') const express = require('express')
const app = express() const app = express()
const publicDirectoryPath = path.join(__dirname, '../public')
app.get('', (req, res) => { app.use(express.static(publicDirectoryPath))
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.get('/weather', (req, res) => { app.get('/weather', (req, res) => {
res.send({ res.send({
location: 'Calgary', forecast: 'It\'s snowing. It\'s really gross out.',
forecast: 'It\'s snowing. It\'s really gross out.' location: 'Calgary'
}) })
}) })