UNPKG

kinto-node-test-server

Version:

A node API for operating a Kinto test server.

62 lines (61 loc) 2.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const cors_1 = __importDefault(require("cors")); const path_1 = __importDefault(require("path")); const body_parser_1 = require("body-parser"); const index_1 = __importDefault(require("./index")); const jsonParser = body_parser_1.json(); class KintoServerProxy { constructor() { this.kintoServer = new index_1.default("http://0.0.0.0:8888/v1", { kintoConfigPath: path_1.default.resolve(path_1.default.join(__dirname, "../kinto.ini")), }); } async startServer() { const app = express_1.default(); app.use(cors_1.default()); app.post("/config", jsonParser, async (req, res) => { const { pathToConfig } = req.body; await this.kintoServer.loadConfig(pathToConfig); res.send("OK"); }); app.post("/start", jsonParser, async (req, res) => { const body = req.body; const http_api_version = await this.kintoServer.start(body); res.send(http_api_version); }); app.get("/ping", async (req, res) => { const http_api_version = await this.kintoServer.ping(); res.send(JSON.stringify({ http_api_version })); }); app.post("/flush", async (req, res) => { const status = await this.kintoServer.flush(); res.status(status.status); res.send(JSON.stringify(status)); }); app.post("/stop", async (req, res) => { await this.kintoServer.stop(); res.send("OK"); }); app.post("/killAll", async (req, res) => { await this.kintoServer.killAll(); res.send("OK"); }); app.get("/logs", async (req, res) => { const logs = await this.kintoServer.logs(); res.send(JSON.stringify({ logs })); }); this.proxyServer = app.listen(8899); } async stopServer() { var _a; await this.kintoServer.stop(); await this.kintoServer.killAll(); (_a = this.proxyServer) === null || _a === void 0 ? void 0 : _a.close(); } } exports.default = KintoServerProxy;