webserv
Version:
a quick, flexible, fully typed development server
71 lines • 3.22 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "path", "util", "../core/log", "./loader", "./utils/addons", "./utils/config", "./utils/externals", "./utils/server"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const util_1 = require("util");
const log_1 = require("../core/log");
const loader_1 = require("./loader");
const addons_1 = require("./utils/addons");
const config_1 = require("./utils/config");
const externals_1 = require("./utils/externals");
const server_1 = require("./utils/server");
/**
* Starts a server from a config.
*
* Lifecycle for start:
*
* 1. load the configuration
* 2. set the log level
* 3. load externals
* 4. boot services
* 5. start the server
*
* @param config a Config or a path that can be used to load a config
* @param app an App to manage the server
*/
function start(config, envConfig = {}) {
return __awaiter(this, void 0, void 0, function* () {
if (typeof config === 'string') {
const configMeta = yield config_1.loadConfig(config);
if (!envConfig.configPath) {
envConfig.configPath = path_1.dirname(configMeta.configPath);
}
config = configMeta.config;
}
if (config.logLevel) {
log_1.setLogLevel(config.logLevel);
}
log_1.log.debug('Using config', util_1.inspect(config, { depth: 5 }));
const env = loader_1.isEnvironment(envConfig)
? envConfig
: Object.assign({ configPath: process.cwd() }, envConfig);
addons_1.checkRegisterTs(config.tsConfig);
externals_1.loadExternals(config.externals, env);
const servers = [];
for (let server of config.servers) {
const controls = yield server_1.bootServer(server, env);
servers.push(controls);
}
return servers;
});
}
exports.default = start;
});
//# sourceMappingURL=index.js.map