UNPKG

edge-runtime

Version:

Run any Edge Function from CLI or Node.js module.

29 lines 1.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runServer = runServer; const create_handler_1 = require("./create-handler"); const async_listen_1 = __importDefault(require("async-listen")); const http_1 = __importDefault(require("http")); const util_1 = require("util"); /** * This helper will create a handler based on the given options and then * immediately run a server on the provided port. If there is no port, the * server will use a random one. */ async function runServer(options) { if (options.port === undefined) options.port = 0; const { handler, waitUntil } = (0, create_handler_1.createHandler)(options); const server = http_1.default.createServer(handler); const url = await (0, async_listen_1.default)(server, options); const closeServer = (0, util_1.promisify)(server.close.bind(server)); return { url: String(url), close: () => Promise.all([waitUntil(), closeServer()]).then(() => void 0), waitUntil, }; } //# sourceMappingURL=run-server.js.map