dipend-graph
Version:
A library for generating a DAG (Directed Acyclic Graph) of dependencies registered in Dipend's dependency container.
58 lines (56 loc) • 2.19 kB
JavaScript
/*
* Copyright 2025 Saulo V. Alvarenga. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DipendGraphServer = void 0;
const tslib_1 = require("tslib");
const http_1 = tslib_1.__importDefault(require("http"));
const process_1 = tslib_1.__importDefault(require("process"));
const handlers_1 = require("./handlers");
class DipendGraphServer {
graphDataHandler;
server;
host;
port;
constructor(dependencyContainer, config) {
const { envHost, envPort } = this.getEnvs();
this.host = config?.host || envHost || "127.0.0.1";
this.port = config?.port || envPort || 4321;
this.graphDataHandler = new handlers_1.GraphDataHandler(dependencyContainer);
this.server = http_1.default.createServer((req, res) => {
const handler = new handlers_1.RequestHandler(this.graphDataHandler);
if (req.url === "/api/data") {
handler.apiDataRouteAction(res);
}
else {
handler.homeRouteAction(req, res);
}
});
}
getEnvs() {
const envHost = process_1.default.env.DIPEND_GRAPH_SERVER_HOST;
const envPort = process_1.default.env.DIPEND_GRAPH_SERVER_PORT
? parseInt(process_1.default.env.DIPEND_GRAPH_SERVER_PORT, 10)
: undefined;
return { envHost, envPort };
}
start() {
this.server.listen(this.port, this.host, () => {
console.log(`Serving the Dipend Graph at http://${this.host}:${this.port}`);
});
}
}
exports.DipendGraphServer = DipendGraphServer;