@copperjs/copper
Version:
A lightweight chromium grid
23 lines • 888 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerSessionProxy = void 0;
const httpProxy = require("http-proxy");
const grid_1 = require("./grid");
const registerSessionProxy = (app, opts, done) => {
const proxy = httpProxy.createProxyServer({});
app.addContentTypeParser('application/json', function (request, payload, done) {
done();
});
app.addContentTypeParser('text/plain', function (request, payload, done) {
done();
});
const handleProxy = (req, reply) => {
const node = grid_1.grid.getNode(req.params.sessionId);
proxy.web(req.raw, reply.raw, { target: node.URL });
};
app.get('/session/:sessionId', handleProxy);
app.all('/session/:sessionId/*', handleProxy);
done();
};
exports.registerSessionProxy = registerSessionProxy;
//# sourceMappingURL=sessionProxy.js.map