-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (34 loc) · 1.1 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
/* A simple web service targetted by the generated simulant test suite.
*
* This service exposes four endpoints:
* - GET / - Returns 200 with JSON body containing the current service
* count.
* - GET /version - Returns JSON describing the service version.
* - PUT /inc - Increment the service count. Returns 204.
* - PUT /dec - Decrement the service count. Returns 204.
*/
var express = require('express');
var morgan = require('morgan');
var PORT = process.env.PORT || 8080;
var git_repo = process.env.GIT_REPO;
var git_sha = process.env.GIT_SHA;
var count = 0;
var app = express();
app.use(morgan('[:date[iso]] :method :url\t:status'));
app.get('/', function (req, res) {
res.status(200).send({count: count});
});
app.get('/version', function (req, res) {
res.status(200).send({repo: git_repo,
sha: git_sha})
});
app.put('/inc', function (req, res) {
count += 1;
res.status(204).end();
});
app.put('/dec', function (req, res) {
count -= 1;
res.status(204).end();
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);