-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (48 loc) · 1.72 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
// server run command || supervisor -- --harmony_destructuring app.js
var express = require('express')
, http = require('http')
, path = require('path')
, reload = require('reload')
, bodyParser = require('body-parser')
, logger = require('morgan')
// , fetch = require('node-fetch')
, fs = require('fs')
, request = require('request')
const Firebase = require('firebase')
const firebase = new Firebase('https://gmres--ridotcom.firebaseio.com/')
var _ = require('lodash')
const pFlagIndex = process.argv.indexOf('-p')
const app = express()
const port = (pFlagIndex !== -1 ) ? process.argv[pFlagIndex + 1] : 1337
const publicDir = path.join(__dirname, '')
app.set('port', process.env.PORT || port)
app.use(logger('dev'))
app.use(bodyParser.json()) //parses json, multi-part (file), url-encoded
app.use('/js/', express.static('prod/js/'))
app.use('/css/', express.static('prod/css/'))
app.get('/', function(req, res) {
console.log('/ REQUESTED')
res.sendFile(path.join(__dirname + '/prod/index.html'));
})
app.get('/*.serviceworker.js', function(req, res) {
console.log('serviceworker requested')
res.sendFile(path.join(__dirname + `/prod${req.originalUrl}`));
})
app.get('/*.html', function(req, res) {
res.sendFile(path.join(__dirname + `/prod${req.originalUrl}`));
})
const data = firebase.child('data').child('places').once('value')
.then((snap) => snap.val())
.then((data) => {
return _.map(data, (item) => item)
})
app.get('/data/', (req, res) => {
console.log('DATA REQUESTED')
data.then((data) => res.json(data))
})
var server = http.createServer(app)
reload(server, app)
server.listen(app.get('port'), function(){
console.log("Web server listening on port " + app.get('port'));
});