Skip to content

HTTP interface do create routes on builder container #6

@beeblebrox3

Description

@beeblebrox3

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions