Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP interface do create routes on builder container #6

Open
beeblebrox3 opened this issue Aug 4, 2017 · 0 comments
Open

HTTP interface do create routes on builder container #6

beeblebrox3 opened this issue Aug 4, 2017 · 0 comments

Comments

@beeblebrox3
Copy link
Owner

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"}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant