forked from ryanj/restify-mongodb-parks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 987 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
34
35
var config = require('config'),
restify = require('restify'),
fs = require('fs'),
db = require('./bin/db.js')
var app = restify.createServer()
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('/initdb', db.initDB);
app.get('/flushdb', db.flushDB);
app.get('/importdata', db.importData);
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: './static/'}));
app.listen(config.port, config.ip, function () {
console.log( "Listening on " + config.ip + ", port " + config.port )
});