From e207123d0c36c940f2d534082d2d18ba7c75e0f1 Mon Sep 17 00:00:00 2001 From: Nhi Tran Date: Wed, 4 Oct 2017 17:06:10 -0400 Subject: [PATCH 1/2] Finish week-04-project --- zip-api/app.js | 21 +++++++++++++++++++-- zip-api/package-lock.json | 30 +++++++++++++++--------------- zip-api/package.json | 2 +- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..a847e18 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -1,7 +1,9 @@ + const express = require('express'); const app = express(); const zipdb = require('./zipData'); +const cit const PORT = process.env.PORT || 8000; @@ -15,15 +17,30 @@ app.get('/', (req, res) => { app.get('/zip/:zipcode', (req, res) => { - // fill in... + const records = zipdb.byZip[req.params.zipcode]; + if(records===undefined){ + res.sendStatus(404); + } + else { + res.json(records); + } }); app.get('/city/:cityname', (req, res) => { - // fill in... + const records = zipdb.byCity[req.params.cityname]; + if(records === undefined) { + res.sendStatus(404) + } else { + res.json(records) + } }); app.listen(PORT, () => { console.log(`zip-api is up and running on ${PORT}`); }); + + + + \ No newline at end of file diff --git a/zip-api/package-lock.json b/zip-api/package-lock.json index 3b11c21..a0dd899 100644 --- a/zip-api/package-lock.json +++ b/zip-api/package-lock.json @@ -1210,13 +1210,6 @@ } } }, - "string_decoder": { - "version": "1.0.1", - "bundled": true, - "requires": { - "safe-buffer": "5.0.1" - } - }, "string-width": { "version": "1.0.2", "bundled": true, @@ -1226,6 +1219,13 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "1.0.1", + "bundled": true, + "requires": { + "safe-buffer": "5.0.1" + } + }, "stringstream": { "version": "0.0.5", "bundled": true, @@ -2162,14 +2162,6 @@ "duplexer": "0.1.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -2179,6 +2171,14 @@ "strip-ansi": "4.0.0" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", diff --git a/zip-api/package.json b/zip-api/package.json index 6fb1e13..37da484 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -4,7 +4,7 @@ "description": "Simple API backend for CTP lecture.", "main": "app.js", "scripts": { - "start": "node app.js" + "start": "nodemon -L app.js" //package watch the file in project, when the file changed it will reloaded automatically }, "author": "Edgardo Molina", "license": "ISC", From 728144c0c045ece0a0d125e59b2675cffb507806 Mon Sep 17 00:00:00 2001 From: nhitran27 Date: Wed, 4 Oct 2017 17:31:30 -0400 Subject: [PATCH 2/2] Update app.js --- zip-api/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zip-api/app.js b/zip-api/app.js index a847e18..33a2f6e 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -3,7 +3,6 @@ const express = require('express'); const app = express(); const zipdb = require('./zipData'); -const cit const PORT = process.env.PORT || 8000; @@ -43,4 +42,4 @@ app.listen(PORT, () => { - \ No newline at end of file +