@lxdhub/web
Version:
<h2 align="center"> <img src="https://i.imgur.com/RGCZZjl.png" alt="LXD Hub Web Logo" width="500" /> </h2>
62 lines • 2.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// These are important and needed before anything else
require("reflect-metadata");
require("zone.js/dist/zone-node");
const common_1 = require("@lxdhub/common");
const Chalk = require("chalk");
const express = require("express");
const path_1 = require("path");
class LXDHubWeb {
constructor(settings, app) {
this.settings = settings;
this.app = app;
this.distFolder = path_1.join(__dirname, '../');
this.browserDistFolder = path_1.join(this.distFolder, 'browser');
this.logger = new common_1.WinstonLogger('LXDHubWeb', settings.logLevel);
this.url = `http://${this.settings.hostUrl}:${this.settings.port}`;
try {
const packageJson = require('../../package.json');
this.settings = Object.assign({}, this.settings, { package_version: packageJson.version });
}
catch (err) {
this.logger.warn('Could not find local package.json');
}
}
setupNgRendering() {
this.app.use(express.static(this.browserDistFolder));
this.app.get('/config.json', (_, res) => res.json(this.settings));
// Match everything, except when it begins with /api
this.app.get(/^(?!\/(api|socket.io)).*$/, (_, res) => res.sendFile(path_1.join(this.browserDistFolder, 'index.html')));
}
async listen() {
this.app.listen(this.settings.port, this.settings.hostUrl, () => this.logger.log(`Running webinterface on ` + Chalk.default.blue(this.url)));
try {
this.logger.log(`Set configuration: ${Chalk.default.blue(JSON.stringify(this.settings))}`);
}
catch (ex) { }
}
async bootstrap() {
if (!this.app) {
this.app = express();
}
this.setupNgRendering();
return this.app;
}
/**
* Runs the webinterface with the set settings
*/
async run() {
try {
await this.bootstrap();
}
catch (err) {
err = err;
this.logger.error(`An error occured while bootstraping the application`);
this.logger.error(err.message);
}
return await this.listen();
}
}
exports.LXDHubWeb = LXDHubWeb;
//# sourceMappingURL=main.js.map