lemon-core
Version:
Lemon Serverless Micro-Service Platform
69 lines • 2.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildExpress = void 0;
/**
* Express Server Application.
* - standalone http service with express.
*
*
* ```bash
* #run-server (use lemon.yml:local)
* $ npm install -g nodemon
* $ ENV=lemon STAGE=local nodemon express.js
* ```
*
* [TODO]
* - [ ] 190801 proper content type `text/plain`
* - [x] 190801 change router underscore char like `loopers_front` -> `loopers-front`
*
*
* @author Steve Jung <steve@lemoncloud.io>
* @date 2019-07-31 support ECMA 2016.
* @date 2019-08-01a auto register api with pattern. `/^[a-z][a-z0-9\-_]+$/`
* @date 2019-08-07 ignore `engine.dt` function.
* @date 2019-11-26 cleanup and optimized for `lemon-core#v2`
* @date 2020-01-23 improve context information via headers.
* @date 2025-05-20 cleanup `express` out of this module.
*
* @copyright (C) lemoncloud.io 2019 - All Rights Reserved.
*/
const test_helper_1 = require("../common/test-helper");
/**
* create Server Instance.
*
* @param $engine - LemonEngine by `buildEngine()`
* @param $web - LambdaWEBHandler in `$cores`
*/
const buildExpress = ($engine, $web, options) => {
const errScope = `buildExpress()`;
// STEP.0 validate parameters.
if (!$engine)
throw new Error(`$engine(LemonEngine) is required - ${errScope}`);
if (!$web)
throw new Error(`$web(LambdaWEBHandler) is required - ${errScope}`);
// STEP.1 check the `lemon-devkit` module.
const _load = (mod) => {
var _a, _b;
if (options === null || options === void 0 ? void 0 : options.loadModule)
return options.loadModule(mod);
try {
return require(mod);
}
catch (e) {
(_a = $engine === null || $engine === void 0 ? void 0 : $engine.err) === null || _a === void 0 ? void 0 : _a.call($engine, `! err =`, e);
const error = `${(_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : (0, test_helper_1.GETERR)(e)}`.toLowerCase();
if (error.includes('cannot find module'))
return null;
throw e;
}
};
const devkit = _load('lemon-devkit');
if (!devkit)
throw new Error(`lemon-devkit(module) is required (npm i -D lemon-devkit) - ${errScope}`);
const _factory = devkit === null || devkit === void 0 ? void 0 : devkit.buildExpress;
if (!_factory)
throw new Error(`@buildExpress (function) is required (invalid devkit) - ${errScope}`);
return _factory($engine, $web, options);
};
exports.buildExpress = buildExpress;
//# sourceMappingURL=express.js.map
;