Created
November 7, 2014 19:06
-
-
Save aliou/661107fa3e1341b54440 to your computer and use it in GitHub Desktop.
simple map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
express = require 'express' | |
session = require 'express-session' | |
morgan = require 'morgan' | |
app = express() | |
foursquare = require('node-foursquare')({ | |
secrets: { | |
clientId: process.env.CONSUMER_KEY, | |
clientSecret: process.env.CONSUMER_SECRET, | |
redirectUrl: 'http://last-places.dev/callback' | |
} | |
}) | |
app.set 'port', (process.env.PORT || 9000) | |
app.use express.static(__dirname + '/public') | |
app.use session({ secret: 'secret', resave: true, saveUninitialized: true }) | |
app.use morgan('combined') | |
app.get '/connect', (req, res) -> | |
res.writeHead(303, { 'location': foursquare.getAuthClientRedirectUrl() }) | |
res.end() | |
app.get '/callback', (req, res) -> | |
foursquare.getAccessToken { code: req.query.code }, (error, accessToken) -> | |
if error | |
res.send('An error was thrown: ' + error.message) | |
else | |
req.session.accessToken = accessToken | |
res.redirect '/' | |
app.get '/data', (req, res) -> | |
foursquare.Users.getCheckins null, null, req.session.accessToken, | |
(error, data) -> | |
checkins = data.checkins.items.map (checkin) -> | |
tmp = checkin.venue.location | |
tmp.name = checkin.venue.name | |
tmp | |
res.json checkins | |
# | |
app.get '/*', (req, res) -> | |
if !req.session.accessToken? | |
res.redirect '/connect' | |
else | |
res.sendFile __dirname + '/map.html' | |
app.listen app.get('port'), -> | |
console.log 'Listening on port ' + app.get('port') + '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>A simple map</title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.css' rel='stylesheet' /> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body ng-app="map"> | |
<div id='map'></div> | |
<script> | |
L.mapbox.accessToken = 'pk.eyJ1IjoiYWxpb3UiLCJhIjoiQ2VNWTFoOCJ9.Kby_4vIat0XTYQPsBg6m5Q'; | |
var map = L.mapbox.map('map', 'examples.map-i86nkdio') | |
.setView([48.85, 2.35], 13); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"coffee-script": "^1.8.0", | |
"express": "^4.10.1", | |
"express-session": "^1.9.1", | |
"morgan": "^1.5.0", | |
"node-foursquare": "^0.2.1", | |
"underscore": "^1.7.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('coffee-script/register') | |
require('./last-places'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ npm install $ source .env $ node server.js