This file contains hidden or 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
| middleware.parseRequest = function(req, res, next) { | |
| if (req.body.latitude && req.body.longitude) { | |
| // build up yelp api query string... | |
| let q = `?term=${SEARCHTERM}&latitude=${req.body.latitude}&longitude=${req.body.longitude}&limit=${APILIMIT}&open_now=true&sort_by=rating` | |
| // how much you're willing to spend | |
| switch (req.body.price) { | |
| case '$': | |
| q += '&price=1' | |
| break |
This file contains hidden or 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
| var m = require('./middleware') // import ./middleware/index.js | |
| // ... | |
| app.post('/random', m.logRequest, m.parseRequest, function(req, res, next) { | |
| req.session.save(function(err) { | |
| res.redirect('/random') | |
| }) | |
| }) |
This file contains hidden or 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
| app.use(session({ | |
| store: new memstore({ | |
| checkPeriod: 3600000 // 1 hour in ms | |
| }), | |
| resave: false, | |
| saveUninitialized: false, | |
| secret: secret | |
| })) |
This file contains hidden or 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
| var ip = process.env.IP || '0.0.0.0' | |
| var port = parseInt(process.env.PORT, 10) || 3000 | |
| var secret = process.env.SECRET || 'some random string' |
This file contains hidden or 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
| // environment config | |
| var ip = process.env.IP || '0.0.0.0', | |
| port = parseInt(process.env.PORT, 10) || 3000, | |
| secret = process.env.SECRET || 'some random long string we should read from the environment' |
This file contains hidden or 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
| /* | |
| * template helpers | |
| */ | |
| // truncate long strings; only add ellipsis on truncation | |
| app.locals.shorten = function(str, len = 30) { | |
| if (str.length > len) { | |
| str = str.substring(0,len).trim() + '...' | |
| } | |
| return str |
This file contains hidden or 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
| function updateMapURL(address) { | |
| let maps = 'https://maps.google.com?q=' | |
| if (bowser.iphone) { | |
| maps = 'maps:q=' | |
| } else if (bowser.android) { | |
| maps = 'geo:0,0?q=' | |
| } | |
| route.addEventListener("click", function() { | |
| location.href = maps + encodeURIComponent(address) | |
| }) |
This file contains hidden or 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
| var geoOpts = { | |
| enableHighAccuracy: true, | |
| maximumAge: 300000, | |
| timeout: 20000 | |
| } |
This file contains hidden or 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
| if (!navigator.geolocation || !navigator.cookieEnabled) { | |
| location.href = '/nolocation' | |
| } else { | |
| navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOpts) | |
| } | |
| function geoSuccess(position) { | |
| latitude.value = position.coords.latitude | |
| longitude.value = position.coords.longitude | |
| loading.innerHTML = 'FIND <i class="fas fa-utensils fa-lg" aria-hidden="true"></i> FOOD' | |
| } |
This file contains hidden or 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
| <% include partials/header %> | |
| <body id="list"> | |
| <script defer src="/js/list.js"></script> | |
| <div id="list-content"> | |
| <% results.forEach(function(biz) { %> | |
| <% if (biz.image_url) { %> | |
| <div class="list-item" style="background-image: url('<%= biz.image_url %>'); background-position: center; background-size: cover"> | |
| <% } else { %> | |
| <div class="list-item" style="background-color: rgba(0, 0, 0, 0.5);"> | |
| <% } %> |