-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Starting a http server on the builder allow create new routes over http, just like wiremock does.
Example:
// server.js
const path = require("path");
const http = require("http");
const Parser = require("./lib/parser");
const FileWriter = require("./lib/fileWriter")(path.join(__dirname, "resources/mappings"));
const parserInstance = new Parser(FileWriter);
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
let bodyChunks = [];
let body;
req.on('data', function (data) {
bodyChunks.push(data);
})
.on('end', function () {
body = JSON.parse(Buffer.concat(bodyChunks).toString());
parserInstance.parse(body.route);
const end = () => {
res.write("ok");
res.end();
};
// reload mappings
http.request({
hostname: "server",
port: 80,
path: '__admin/mappings/reset',
method: 'POST'
}, end);
});
}).listen(80);curl -X POST http://localhost:80/route -H "Content-Type: application/json" -d '{"route": {"name": "foo"}}'Metadata
Metadata
Assignees
Labels
No labels