This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
brunch-server.js
58 lines (47 loc) · 1.74 KB
/
brunch-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
'use strict';
var bodyParser = require('body-parser');
var express = require('express');
var fs = require('fs');
var http = require('http');
var logger = require('morgan');
var Path = require('path');
module.exports = function startServer(port, path, callback) {
var app = express();
var server = http.createServer(app);
var mocks = {
health: JSON.parse(fs.readFileSync("mock/health.json")),
packages: JSON.parse(fs.readFileSync("mock/packages.json")),
services: [
{name: "Mesos", id: "mesos", check: "mesos", path: "/mesos"},
{name: "Marathon", id: "marathon", check: "marathon", path: "/marathon"},
{name: "Consul", id: "consul", check: "consul", path: "/consul"},
{name: "Chronos", id: "chronos", check: "chronos", path: "/chronos"},
{name: "Traefik", id: "traefik", check: "traefik-admin", path: "/traefik"}
]
};
app.use(express.static(Path.join(__dirname, path)));
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/_internal/services.json', function(req, res) {
res.json(mocks.services);
});
app.get('/consul/v1/health/state/any', function(req, res) {
res.json(mocks.health);
});
app.get('/1/packages', function(req, res) {
res.json(mocks.packages);
});
app.get('/1/packages/:name', function(req, res) {
var name = req.params.name;
for (var i in mocks.packages) {
var app = mocks.packages[i];
if (app.name === name) {
res.json(app);
return;
}
}
res.status(400).end();
});
server.listen(port, callback);
return server;
};