UNPKG

1.05 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const express_1 = require("express");
7const router = express_1.Router();
8const DockerCompiler_1 = __importDefault(require("./DockerCompiler"));
9const CachingUrlFetcher_1 = __importDefault(require("./CachingUrlFetcher"));
10const compiler = new DockerCompiler_1.default(new CachingUrlFetcher_1.default());
11router.use(express_1.json());
12/**
13 * Run a method of `DockerCompiler`
14 * @param method The method to run e.g `compile`, `build`
15 */
16function run(method) {
17 return async (req, res) => {
18 try {
19 // @ts-ignore
20 const node = await compiler[method](req.body);
21 res.status(200).json(node);
22 }
23 catch (error) {
24 res.status(500).write(error.stack);
25 }
26 };
27}
28router.put('/compile', run('compile'));
29router.put('/compile', run('execute'));
30exports.default = router;