forked from heroku/node-js-getting-started
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
22 lines (20 loc) · 857 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const express = require('express')
const path = require('path')
const PORT = process.env.PORT || 5000
const toiletURL = 'https://geosite.pncc.govt.nz/arcgis/rest/services/Public/WEB_Parks/MapServer/1/query?where=1%3D1&outFields=*&outSR=4326&f=json'
const request = require('request')
let toiletData = {}
// Get the toilet data
request(toiletURL, { json: true }, (err, resp, body) => {
if (err) { return console.log(err) }
toiletData = body.features
express().use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index', {
toiletx: toiletData[0].geometry.x,
toilety: toiletData[0].geometry.y,
toilets: JSON.stringify(toiletData)
}))
.listen(PORT, () => console.log(`Listening on ${ PORT }`))
});