UNPKG

valory-adaptor-slimjim

Version:
40 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const valory_runtime_1 = require("valory-runtime"); const slimjim = require("slimjim"); const pathReplacer = /{([\S]*?)}/g; class SlimJimAdaptor { constructor() { this.allowDocSite = true; this.disableSerialization = false; this.locallyRunnable = true; this.server = new slimjim.SlimJim(); } register(path, method, handler) { const route = `${path}:${valory_runtime_1.HttpMethod[method]}`; path = path.replace(pathReplacer, ":$1"); this.server.endpoint(valory_runtime_1.HttpMethod[method], path, (req, done) => { const transRequest = new valory_runtime_1.ApiRequest({ body: req.body, formData: req.body, query: req.query, path: req.params, rawBody: req.rawBody, headers: req.headers, route, }); handler(transRequest).then((response) => { done(null, response); }); }); } getExport(metadata, options) { this.server.start(options.port || process.env.PORT, options.host || process.env.HOST); return { valory: metadata }; } shutdown() { return; } } exports.SlimJimAdaptor = SlimJimAdaptor; //# sourceMappingURL=adaptor-slimjim.js.map