-
Notifications
You must be signed in to change notification settings - Fork 108
BETTER debugging and general Improvements #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| .DS_Store | ||
|
|
||
| # configuration files | ||
| server/config/config.js | ||
| config.js | ||
|
|
||
| # node | ||
| node_modules | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| var path = require('path'), | ||
| express = require('express'), | ||
| var express = require('express'), | ||
| mongoose = require('mongoose'), | ||
| morgan = require('morgan'), | ||
| bodyParser = require('body-parser'), | ||
|
|
@@ -14,6 +13,9 @@ module.exports.init = function() { | |
| //initialize app | ||
| var app = express(); | ||
|
|
||
| // Readable JSON output | ||
| app.set('json spaces', 4); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better JSON output. Although not necessarily need, better for general debugging JSON |
||
|
|
||
| //enable request logging for development debugging | ||
| app.use(morgan('dev')); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,20 @@ module.exports = function(req, res, next) { | |
| } | ||
|
|
||
| var data = JSON.parse(body); | ||
| req.results = data.results[0].geometry.location; | ||
| if (data.results.length > 0) { | ||
| var coordinates = data.results[0].geometry.location; | ||
| req.results = { latitude: coordinates.lat, longitude: coordinates.lng}; | ||
| } else if (data.status == 'REQUEST_DENIED') { | ||
| var debug_message = [ | ||
| "You need a Google Geocoding API key for this Assignment", | ||
| "Get a key at: https://developers.google.com/maps/documentation/geocoding/get-api-key", | ||
| "You'd also need a Google Cloud Platform project, with the 'Google Geocoding API' enabled" | ||
| ]; | ||
| console.log(debug_message.join("\n")); | ||
| } else { | ||
| req.results = undefined | ||
| console.log(data); | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above is the main reason for this PR (see whole file diff) |
||
| next(); | ||
| }); | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,8 @@ exports.create = function(req, res) { | |
| var listing = new Listing(req.body); | ||
|
|
||
| /* save the coordinates (located in req.results if there is an address property) */ | ||
| if(req.results) { | ||
| listing.coordinates = { | ||
| latitude: req.results.lat, | ||
| longitude: req.results.lng | ||
| }; | ||
| if (req.results) { | ||
| listing.coordinates = req.results; | ||
| } | ||
|
|
||
| /* Then save the listing */ | ||
|
|
@@ -47,16 +44,16 @@ exports.read = function(req, res) { | |
| exports.update = function(req, res) { | ||
| var listing = req.listing; | ||
|
|
||
| /* Replace the article's properties with the new properties found in req.body */ | ||
| /* Replace the listing's properties with the new properties found in req.body */ | ||
| /* save the coordinates (located in req.results if there is an address property) */ | ||
| /* Save the article */ | ||
| /* Save the listing */ | ||
| }; | ||
|
|
||
| /* Delete a listing */ | ||
| exports.delete = function(req, res) { | ||
| var listing = req.listing; | ||
|
|
||
| /* Remove the article */ | ||
| /* Remove the listing */ | ||
| }; | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of typos on this file |
||
| /* Retreive all the directory listings, sorted alphabetically by listing code */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignores ALL config files