From 8f136ffed89050f5184c1af0a0ee054b41428f1a Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sun, 29 Sep 2019 18:53:20 -0600 Subject: [PATCH] Video 45: Serving up Static Assets --- web-server/public/about.html | 8 ++++++++ web-server/public/help.html | 8 ++++++++ web-server/public/index.html | 8 ++++++++ web-server/src/app.js | 24 ++++++------------------ 4 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 web-server/public/about.html create mode 100644 web-server/public/help.html create mode 100644 web-server/public/index.html diff --git a/web-server/public/about.html b/web-server/public/about.html new file mode 100644 index 0000000..2ed79d1 --- /dev/null +++ b/web-server/public/about.html @@ -0,0 +1,8 @@ + + + + + +

About

+ + diff --git a/web-server/public/help.html b/web-server/public/help.html new file mode 100644 index 0000000..463d2e5 --- /dev/null +++ b/web-server/public/help.html @@ -0,0 +1,8 @@ + + + + + +

Help

+ + diff --git a/web-server/public/index.html b/web-server/public/index.html new file mode 100644 index 0000000..e5c7b82 --- /dev/null +++ b/web-server/public/index.html @@ -0,0 +1,8 @@ + + + + + +

From a static file

+ + diff --git a/web-server/src/app.js b/web-server/src/app.js index 63a70ef..adce4e6 100644 --- a/web-server/src/app.js +++ b/web-server/src/app.js @@ -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('

Weather

') -}) - -app.get('/help', (req, res) => { - res.send([{ - name: 'Jason', - age: 38 - }, { - name: 'Sarah' - }]) -}) - -app.get('/about', (req, res) => { - res.send('

About

') -}) +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' }) })