UNPKG

gypsum

Version:

Simple and easy lightweight typescript server side framework on Node.js.

61 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const express = require("express"); const url_1 = require("tools-box/url"); const object_1 = require("tools-box/object"); const config_1 = require("./config"); const config_2 = require("./auth/config"); const config_3 = require("./storage/config"); class AppState { constructor() { this._sockets = {}; this.router = express.Router(); this.root = process.cwd(); this.env = process.env.NODE_ENV || 'developemt'; this.ioNamespaces = {}; this.config = {}; this.apps = []; this.storage = {}; this.auth = {}; this.hooks = []; this.currentContext = null; } getApp(name) { return this.apps.find(app => app.name.toLowerCase() === name.toLowerCase()) || null; } getModel(path) { let appName, modelName; [appName, modelName] = path.split('.'); let app = this.apps.find(_app => _app.name.toLowerCase() === appName.toLowerCase()); if (app) return app.$getModel(modelName.toLowerCase()); return null; } getHook(name) { return this.hooks.find(hook => hook.name.toLowerCase() === name.toLowerCase()) || null; } setConfiguration(userConfig = {}) { object_1.extend(this.config, config_1.Config.dev); if (userConfig.dev) object_1.extend(this.config, userConfig.dev); if (this.env === 'production' && userConfig.prod) object_1.extend(this.config, userConfig.prod); this.config.files_data_dir = url_1.URL.Clean(this.config.files_data_dir); } setAuthConfig(auth = {}) { this.auth = object_1.extend(config_2.defaultAuthConfig, auth.dev || {}); if (this.env === 'production' && auth.prod) object_1.extend(this.auth, auth.prod); } setStorageConfig(storageConfig = {}) { this.storage = object_1.extend(config_3.defaultStorageConfig, storageConfig.dev || {}); if (this.env === 'production' && storageConfig.prod) object_1.extend(this.storage, storageConfig.prod); this.storage.storageDir = path.join(this.root, this.storage.storageDir); } } exports.AppState = AppState; const State = new AppState(); exports.State = State; //# sourceMappingURL=state.js.map