Skip to content
Browse files

parse city from url

  • Loading branch information...
1 parent dfac121 commit 2184590741c274660fef7d3a14f96f240d8ef3ca @JustinBeckwith committed Sep 21, 2012
Showing with 18 additions and 4 deletions.
  1. +3 −1 backend/routes/home.js
  2. +15 −3 frontend/views/images.html
View
4 backend/routes/home.js
@@ -34,7 +34,9 @@ module.exports = function (app, nconf, serviceBusService) {
pic: b
}
console.log(pic);
- var message = { body: JSON.stringify(pic) };
+ var message = {
+ body: JSON.stringify(pic)
+ };
serviceBusService.sendTopicMessage('wazages', message, function (error) {
if (error) {
console.log('error sending message to topic - ' + error);
View
18 frontend/views/images.html
@@ -9,11 +9,23 @@
$(function () {
var socket = io.connect();
socket.on('connect', function () {
- console.log('connected!');
- socket.emit('setCity', { city: 'seattle' });
+ var city = '';
+ var urlParts = window.location.href.split("/");
+ for (var i = urlParts.length - 1; i >= 0; i--) {
+ if (urlParts[i]) {
+ city = urlParts[i];
+ break;
+ }
+ }
+ if (!city) {
+ alert('invalid url! please give me a city.')
+ } else {
+ console.log('getting data for ' + city);
+ socket.emit('setCity', { city: city });
+ }
});
socket.on('newPic', function (pic) {
- console.log('got a new pic!!!')
+ console.log('got a new pic!!!')
var p = JSON.parse(pic);
console.log(p);
$("#pics").append($("<img src=\"" + p.data.images.low_resolution.url + "\">"));

0 comments on commit 2184590

Please sign in to comment.
Something went wrong with that request. Please try again.