UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

41 lines 1.3 kB
import http from "node:http"; import finalhandler from "finalhandler"; import serveStatic from "serve-static"; export function startLocalServer(options = { path: "./", port: 8001 }) { const serve = serveStatic(options.path); const server = http.createServer(function (req, res) { const done = finalhandler(req, res); serve(req, res, done); }); server.listen(options.port); } /** * Local file server, for quickly serving static files */ export default class LocalFileServer { _server; constructor(options) { const { path = "./", port = 8001 } = options; const serve = serveStatic(path); this._server = http.createServer(function (req, res) { const done = finalhandler(req, res, { onerror: LocalFileServer.logerror, }); serve(req, res, done); }); this._server.listen(port); this._server.setTimeout(5000, () => { console.log("Timeout after 5 seconds"); this._server.close(() => { console.log("Server is closed"); }); }); } close() { this._server.close(); } static logerror(err) { console.error(err.stack || err.toString()); } } //# sourceMappingURL=localServer.js.map