Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions zip-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,53 @@ const zipdb = require('./zipData');
const PORT = process.env.PORT || 8000;


// console.log(zipdb.byCity);


app.get('/', (req, res) => {
res.json({test: 'Yay'});
res.json({ test: 'Yay' });
});


app.get('/zip/:zipcode', (req, res) => {
// fill in...
});




app.get('/city/:cityname', (req, res) => {
// fill in...
const cities = req.params.cityname.toUpperCase();


if (/^[a-zA-Z]+$/.test(cities)) {

const results = zipdb.byCity[cities];
if (results === undefined) {
res.json("city not found!");
}
res.json(results);
} else {
res.json("city not found!");
}
});


app.listen(PORT, () => {
console.log(`zip-api is up and running on ${PORT}`);
console.log(`zip-api is up and running on http://localhost:${PORT}`);
});

app.get('/zip/:zipcode', (req, res) => {
const zipcode = req.params.zipcode;


if (zipcode.length === 5) {

const results = zipdb.byZip[zipcode];
if (results === undefined) {
res.json("zip not found!");
}
res.json(results);
} else {
res.json("zip not found!");
}



});
2 changes: 1 addition & 1 deletion zip-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"devDependencies": {
"nodemon": "^1.19.4"
}
}
}