-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (43 loc) · 1.45 KB
/
app.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
var express = require('express');
var bodyParser = require('body-parser');
var cfenv = require("cfenv");
var path = require('path');
var cors = require('cors');
//---Deployment Tracker---------------------------------------------------------
require("cf-deployment-tracker-client").track();
// Setup the required environment variables
var vcapLocal = null;
try {
vcapLocal = require("./vcap-local.json");
}
catch (e) {}
var appEnvOpts = vcapLocal ? {vcap:vcapLocal} : {};
var appEnv = cfenv.getAppEnv(appEnvOpts);
try {
cloudantService = appEnv.services.cloudantNoSQLDB[0];
}
catch (e) {
console.error("Error looking up service: ", e);
}
// Setup route handlers
var policies = require('./routes/policies');
// Setup express middleware.
var app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'www')));
// REST HTTP Methods
app.get('/db/:option', policies.dbOptions);
app.get('/policies', policies.list);
app.get('/fib', policies.fib);
app.get('/loadTest', policies.loadTest);
app.get('/policies/:id', policies.find);
app.post('/policies', policies.create);
app.put('/policies/:id', policies.update);
app.delete('/policies/:id', policies.remove);
// start server on the specified port and binding host
app.listen(appEnv.port, "0.0.0.0", function () {
// print a message when the server starts listening
console.log("catalog server starting on " + appEnv.url);
});