systemquery/src/lib/agent/subsystems/http/HttpSubsystem.mjs

25 lines
603 B
JavaScript

"use strict";
import http from 'http';
import log from '../../../io/NamespacedLog.mjs'; const l = log("http");
import make_router from './routes.mjs';
class HttpSubsystem {
constructor(sys) {
this.sys = sys;
this.router = make_router(this.sys);
}
init(port, address = `::1`) {
this.http = http.createServer(async (req, res) => {
await this.router.handle(req, res);
});
const address_pretty = address.indexOf(`:`) > -1 ? `[${address}]` : address;
this.http.listen(port, address, () => l.log(`Listening on http://${address_pretty}:${port}`));
}
}
export default HttpSubsystem;