forked from OpenShiftDemos/restify-mongodb-parks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 935 Bytes
/
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
var restify = require('restify'),
fs = require('fs'),
config = require('./bin/config.js'),
db = require('./bin/db.js');
var app = restify.createServer();
db.initDB('keepAlive');
app.use(restify.queryParser())
app.use(restify.CORS())
app.use(restify.fullResponse())
// Routes
app.get('/parks/within', db.selectBox);
app.get('/parks', db.selectAll);
app.get('/status', function (req, res, next)
{
res.send("{status: 'ok'}");
});
app.get('/', function (req, res, next)
{
var data = fs.readFileSync(__dirname + '/index.html');
res.status(200);
res.header('Content-Type', 'text/html');
res.end(data.toString().replace(/host:port/g, req.header('Host')));
});
app.get(/\/(css|js|img)\/?.*/, restify.serveStatic({directory: __dirname+'/static/'}));
app.listen(config.get('PORT'), config.get('IP'), function () {
console.log( "Listening on " + config.get('IP') + ", port " + config.get('PORT'))
});