From 828f919706f8729f86c4cc81199075a4db0ecec7 Mon Sep 17 00:00:00 2001 From: Paul Wallace <paulwallace@Pauls-MacBook-Air.local> Date: Thu, 3 Nov 2016 12:05:06 -0700 Subject: [PATCH] Add routes for crime data api call --- index.js | 6 +++++- routes/crime.js | 24 ++++++++++++++++++++++++ views/pages/tempcrime.ejs | 11 +++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 routes/crime.js create mode 100644 views/pages/tempcrime.ejs diff --git a/index.js b/index.js index 3f6c72e..0253b54 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ var express = require('express'); +var crime = require('./routes/crime'); + var app = express(); app.set('port', (process.env.PORT || 5000)); -app.use(express.static(__dirname + '/public')); +app.use(express.static(__dirname + '../public')); // views is directory for all template files app.set('views', __dirname + '/views'); @@ -18,6 +20,8 @@ app.get('/landing', function(request, response) { response.render('pages/landing'); }); +app.get('/api', crime.view); + app.listen(app.get('port'), function() { console.log('Node app is running on port', app.get('port')); }); diff --git a/routes/crime.js b/routes/crime.js new file mode 100644 index 0000000..97decab --- /dev/null +++ b/routes/crime.js @@ -0,0 +1,24 @@ +var unirest = require('unirest'); + +exports.view = function(req, res){ + + unirest.get("https://yourmapper2.p.mashape.com/datasetlist?format=json&maxlat=40&maxlon=-70&minlat=30&minlon=-90&num=5&sort=location") + .header("X-Mashape-Key", "gj4g6D3zxKmshys7yyf9KNbuywOxp1ueazFjsn6n2fK4sccIGA") + .header("Accept", "application/json") + .end(function (result) { + // console.log(result.status, result.headers, result.body); + + }); + + + + // These code snippets use an open-source library. http://unirest.io/nodejs + unirest.get("https://crimescore.p.mashape.com/crimescore?f=json&id=174&lat=38.08809&lon=-85.679626") + .header("X-Mashape-Key", "gj4g6D3zxKmshys7yyf9KNbuywOxp1ueazFjsn6n2fK4sccIGA") + .header("Accept", "application/json") + .end(function (result) { + res.render('pages/tempcrime', result); + }); + + +}; \ No newline at end of file diff --git a/views/pages/tempcrime.ejs b/views/pages/tempcrime.ejs new file mode 100644 index 0000000..0ff90f7 --- /dev/null +++ b/views/pages/tempcrime.ejs @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <% include ../partials/header %> + </head> + + <body> + <%= body %> + </body> + + </html> \ No newline at end of file -- 1.9.1