@expressots/adapter-express 1.8.2 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CHANGELOG.md +168 -139
- package/lib/cjs/adapter-express/application-express.base.js +2 -12
- package/lib/cjs/adapter-express/application-express.js +132 -52
- package/lib/cjs/adapter-express/application-express.types.js +0 -20
- package/lib/cjs/adapter-express/express-utils/base-middleware.js +2 -2
- package/lib/cjs/adapter-express/express-utils/constants.js +1 -3
- package/lib/cjs/adapter-express/express-utils/decorators.js +26 -12
- package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +10 -5
- package/lib/cjs/adapter-express/express-utils/utils.js +3 -0
- package/lib/cjs/adapter-express/index.js +4 -1
- package/lib/cjs/adapter-express/micro-api/application-express-micro-container.js +51 -0
- package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +101 -0
- package/lib/cjs/adapter-express/micro-api/application-express-micro.js +177 -0
- package/lib/cjs/adapter-express/micro-api/index.js +5 -0
- package/lib/cjs/adapter-express/render/constants.js +40 -0
- package/lib/cjs/adapter-express/render/engine.js +52 -11
- package/lib/cjs/adapter-express/render/index.js +0 -3
- package/lib/cjs/di/di.interfaces.js +10 -0
- package/lib/cjs/types/adapter-express/application-express.base.d.ts +17 -0
- package/lib/cjs/types/adapter-express/application-express.d.ts +58 -23
- package/lib/cjs/types/adapter-express/application-express.types.d.ts +1 -41
- package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +18 -4
- package/lib/cjs/types/adapter-express/express-utils/http-status-middleware.d.ts +2 -0
- package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +1 -1
- package/lib/cjs/types/adapter-express/index.d.ts +2 -2
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +93 -0
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +79 -0
- package/lib/cjs/types/adapter-express/micro-api/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/render/constants.d.ts +26 -0
- package/lib/cjs/types/adapter-express/render/engine.d.ts +14 -22
- package/lib/cjs/types/adapter-express/render/index.d.ts +4 -4
- package/lib/cjs/types/di/di.interfaces.d.ts +289 -0
- package/lib/package.json +11 -16
- package/package.json +11 -16
- package/lib/cjs/adapter-express/application-express.interface.js +0 -2
- package/lib/cjs/adapter-express/render/ejs/ejs.config.js +0 -37
- package/lib/cjs/adapter-express/render/ejs/ejs.types.js +0 -3
- package/lib/cjs/adapter-express/render/handlebars/hbs.config.js +0 -38
- package/lib/cjs/adapter-express/render/pug/pug.config.js +0 -25
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts +0 -20
- package/lib/cjs/types/adapter-express/render/ejs/ejs.config.d.ts +0 -21
- package/lib/cjs/types/adapter-express/render/ejs/ejs.types.d.ts +0 -169
- package/lib/cjs/types/adapter-express/render/handlebars/hbs.config.d.ts +0 -20
- package/lib/cjs/types/adapter-express/render/pug/pug.config.d.ts +0 -17
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Route = void 0;
|
|
4
|
+
const core_1 = require("@expressots/core");
|
|
5
|
+
class Route {
|
|
6
|
+
constructor(app) {
|
|
7
|
+
this.logger = new core_1.Logger();
|
|
8
|
+
this.routes = [];
|
|
9
|
+
this.globalPrefix = "";
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Set the global route prefix
|
|
14
|
+
* @param prefix
|
|
15
|
+
* @public API
|
|
16
|
+
*/
|
|
17
|
+
setGlobalRoutePrefix(prefix) {
|
|
18
|
+
this.globalPrefix = prefix;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Define a route
|
|
22
|
+
* @param method - HTTP method
|
|
23
|
+
* @param path - Route path
|
|
24
|
+
* @param handler - Route handler
|
|
25
|
+
* @param middleware - Route middleware
|
|
26
|
+
* @public API
|
|
27
|
+
*/
|
|
28
|
+
define(method, path, handler, ...middleware) {
|
|
29
|
+
const normalizedPath = `${this.globalPrefix.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
30
|
+
this.routes.push({ method, path: normalizedPath, handler, middleware });
|
|
31
|
+
this.logger.info(`Route ${method.toUpperCase()} '${normalizedPath}' added.`, "Route");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Define a GET route
|
|
35
|
+
* @param path - Route path
|
|
36
|
+
* @param handler - Route handler
|
|
37
|
+
* @param middleware - Route middleware
|
|
38
|
+
* @public API
|
|
39
|
+
*/
|
|
40
|
+
get(path, handler, ...middleware) {
|
|
41
|
+
this.define("get", path, handler, ...middleware);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Define a POST route
|
|
45
|
+
* @param path - Route path
|
|
46
|
+
* @param handler - Route handler
|
|
47
|
+
* @param middleware - Route middleware
|
|
48
|
+
* @public API
|
|
49
|
+
*/
|
|
50
|
+
post(path, handler, ...middleware) {
|
|
51
|
+
this.define("post", path, handler, ...middleware);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Define a PUT route
|
|
55
|
+
* @param path - Route path
|
|
56
|
+
* @param handler - Route handler
|
|
57
|
+
* @param middleware - Route middleware
|
|
58
|
+
* @public API
|
|
59
|
+
*/
|
|
60
|
+
put(path, handler, ...middleware) {
|
|
61
|
+
this.define("put", path, handler, ...middleware);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Define a DELETE route
|
|
65
|
+
* @param path - Route path
|
|
66
|
+
* @param handler - Route handler
|
|
67
|
+
* @param middleware - Route middleware
|
|
68
|
+
* @public API
|
|
69
|
+
*/
|
|
70
|
+
delete(path, handler, ...middleware) {
|
|
71
|
+
this.define("delete", path, handler, ...middleware);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Define a PATCH route
|
|
75
|
+
* @param path - Route path
|
|
76
|
+
* @param handler - Route handler
|
|
77
|
+
* @param middleware - Route middleware
|
|
78
|
+
* @public API
|
|
79
|
+
*/
|
|
80
|
+
patch(path, handler, ...middleware) {
|
|
81
|
+
this.define("patch", path, handler, ...middleware);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Apply the routes to the Express application
|
|
85
|
+
*/
|
|
86
|
+
applyRoutes() {
|
|
87
|
+
this.routes.forEach(({ method, path, handler, middleware }) => {
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
this.app[method](path, ...middleware, handler);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the routes
|
|
94
|
+
* @returns Array of route definitions
|
|
95
|
+
* @public API
|
|
96
|
+
*/
|
|
97
|
+
get Routes() {
|
|
98
|
+
return this.routes;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Route = Route;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMicroAPI = createMicroAPI;
|
|
7
|
+
const core_1 = require("@expressots/core");
|
|
8
|
+
const shared_1 = require("@expressots/shared");
|
|
9
|
+
const express_1 = __importDefault(require("express"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const application_express_micro_container_1 = require("./application-express-micro-container");
|
|
12
|
+
const application_express_micro_route_1 = require("./application-express-micro-route");
|
|
13
|
+
class AppExpressMicro {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.logger = new core_1.Logger();
|
|
16
|
+
this.globalPrefix = "/";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handle the exit of the server
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
handleExit() {
|
|
23
|
+
this.logger.info("Server shutting down.", "MicroAPI");
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configure the middleware for the application
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
configureMiddleware() {
|
|
31
|
+
const sortedMiddlewarePipeline = this.middlewareManager.getMiddlewarePipeline();
|
|
32
|
+
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
33
|
+
for (const entry of pipeline) {
|
|
34
|
+
if (typeof entry === "function") {
|
|
35
|
+
this.app.use(entry);
|
|
36
|
+
}
|
|
37
|
+
else if (entry.middlewares) {
|
|
38
|
+
const { path, middlewares } = entry;
|
|
39
|
+
for (const mid of middlewares) {
|
|
40
|
+
if (path) {
|
|
41
|
+
this.app.use(path, mid);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.app.use(mid);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set the global route prefix
|
|
52
|
+
* @param prefix - The global route prefix
|
|
53
|
+
* @public API
|
|
54
|
+
*/
|
|
55
|
+
setGlobalRoutePrefix(prefix) {
|
|
56
|
+
this.globalPrefix = prefix;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the environment for the application
|
|
60
|
+
* @param environment - The environment to initialize
|
|
61
|
+
* @param options - Options for the environment initialization
|
|
62
|
+
* @public API
|
|
63
|
+
*/
|
|
64
|
+
initEnvironment(environment, options) {
|
|
65
|
+
this.environment = environment;
|
|
66
|
+
if (options === undefined) {
|
|
67
|
+
(0, shared_1.config)({ path: ".env" });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (!options.env[environment]) {
|
|
71
|
+
this.logger.error(`Environment configuration for [${environment}] does not exist.`, "adapter-express");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const envFileName = options.env[environment];
|
|
76
|
+
if (!fs_1.default.existsSync(envFileName)) {
|
|
77
|
+
this.logger.error(`Environment file [${envFileName}] does not exist.`, "adapter-express");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
(0, shared_1.config)({ path: envFileName });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the Middleware instance
|
|
88
|
+
* @returns IMiddleware
|
|
89
|
+
* @public API
|
|
90
|
+
*/
|
|
91
|
+
get Middleware() {
|
|
92
|
+
return this.middlewareManager;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the Route instance
|
|
96
|
+
* @returns IRoute
|
|
97
|
+
* @public API
|
|
98
|
+
*/
|
|
99
|
+
get Route() {
|
|
100
|
+
return this.routeManager;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the Container instance
|
|
104
|
+
* @returns IIOC
|
|
105
|
+
* @public API
|
|
106
|
+
*/
|
|
107
|
+
get Container() {
|
|
108
|
+
return this.container;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the Express HTTP Server instance
|
|
112
|
+
* @returns express.Application
|
|
113
|
+
* @public API
|
|
114
|
+
*/
|
|
115
|
+
getHttpServer() {
|
|
116
|
+
return this.app;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a new instance of the Express Micro API adapter
|
|
120
|
+
* @param config - Configuration options
|
|
121
|
+
* @returns ICreateMicroAPI
|
|
122
|
+
* @public API
|
|
123
|
+
*/
|
|
124
|
+
create(config) {
|
|
125
|
+
this.app = (0, express_1.default)();
|
|
126
|
+
this.routeManager = new application_express_micro_route_1.Route(this.app);
|
|
127
|
+
this.container = new application_express_micro_container_1.IOC(config?.containerOptions);
|
|
128
|
+
this.middlewareManager = new core_1.Middleware();
|
|
129
|
+
this.environment = "development";
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Build the Web Server Micro API
|
|
134
|
+
* @returns IWebServerMicroAPI
|
|
135
|
+
* @public API
|
|
136
|
+
*/
|
|
137
|
+
build() {
|
|
138
|
+
this.routeManager.setGlobalRoutePrefix(this.globalPrefix);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Listen for incoming requests
|
|
143
|
+
* @param port - The port to listen on
|
|
144
|
+
* @param appInfo - Information about the application
|
|
145
|
+
* @public API
|
|
146
|
+
*/
|
|
147
|
+
async listen(port, appInfo) {
|
|
148
|
+
const logger = new core_1.Logger();
|
|
149
|
+
this.port = typeof port === "string" ? parseInt(port, 10) : port || 3000;
|
|
150
|
+
this.configureMiddleware();
|
|
151
|
+
this.routeManager.applyRoutes();
|
|
152
|
+
if (this.Middleware.getErrorHandler()) {
|
|
153
|
+
this.app.use(this.Middleware.getErrorHandler());
|
|
154
|
+
}
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
this.app.listen(this.port, () => {
|
|
157
|
+
const appInfoNormalized = appInfo ? `${appInfo?.appName} - ${appInfo?.appVersion} ` : "";
|
|
158
|
+
logger.info(`${appInfoNormalized}[${this.port}:${this.environment}]`, "MicroAPI");
|
|
159
|
+
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
160
|
+
process.on(signal, this.handleExit.bind(this));
|
|
161
|
+
});
|
|
162
|
+
resolve();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Create a new instance of the Express Micro API adapter
|
|
169
|
+
* @param config - Configuration options
|
|
170
|
+
* @returns ICreateMicroAPI
|
|
171
|
+
* @public API
|
|
172
|
+
*/
|
|
173
|
+
function createMicroAPI(config) {
|
|
174
|
+
const microAPI = new AppExpressMicro();
|
|
175
|
+
const create = microAPI.create.bind(microAPI);
|
|
176
|
+
return create(config);
|
|
177
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMicroAPI = void 0;
|
|
4
|
+
var application_express_micro_1 = require("./application-express-micro");
|
|
5
|
+
Object.defineProperty(exports, "createMicroAPI", { enumerable: true, get: function () { return application_express_micro_1.createMicroAPI; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PUG_DEFAULTS = exports.DEFAULT_PARTIALS_DIR = exports.HANDLEBARS_DEFAULTS = exports.EJS_DEFAULTS = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* Ejs defaults
|
|
7
|
+
* @type {EjsOptions}
|
|
8
|
+
* @constant
|
|
9
|
+
* @default
|
|
10
|
+
*/
|
|
11
|
+
exports.EJS_DEFAULTS = {
|
|
12
|
+
viewsDir: (0, path_1.join)(process.cwd(), "views"),
|
|
13
|
+
viewEngine: "ejs",
|
|
14
|
+
serverOptions: {},
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Handlebars defaults
|
|
18
|
+
* @type {HandlebarsOptions}
|
|
19
|
+
* @constant
|
|
20
|
+
* @default
|
|
21
|
+
*/
|
|
22
|
+
exports.HANDLEBARS_DEFAULTS = {
|
|
23
|
+
viewEngine: "hbs",
|
|
24
|
+
viewsDir: (0, path_1.join)(process.cwd(), "views"),
|
|
25
|
+
partialsDir: (0, path_1.join)(process.cwd(), "views/partials"),
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Default partials directory
|
|
29
|
+
*/
|
|
30
|
+
exports.DEFAULT_PARTIALS_DIR = (0, path_1.join)(process.cwd(), "views/partials");
|
|
31
|
+
/**
|
|
32
|
+
* Pug defaults
|
|
33
|
+
* @type {PugOptions}
|
|
34
|
+
* @constant
|
|
35
|
+
* @default
|
|
36
|
+
*/
|
|
37
|
+
exports.PUG_DEFAULTS = {
|
|
38
|
+
viewEngine: "pug",
|
|
39
|
+
viewsDir: (0, path_1.join)(process.cwd(), "views"),
|
|
40
|
+
};
|
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.setEngineEjs = setEngineEjs;
|
|
4
|
+
exports.setEngineHandlebars = setEngineHandlebars;
|
|
5
|
+
exports.setEnginePug = setEnginePug;
|
|
6
|
+
const core_1 = require("@expressots/core");
|
|
7
|
+
const resolve_render_1 = require("./resolve-render");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @public
|
|
10
|
+
* Set Ejs as the view engine
|
|
11
|
+
* @param {Application} app - The express application
|
|
12
|
+
* @param {EjsOptions} [options=EJS_DEFAULTS] - The ejs options
|
|
9
13
|
*/
|
|
10
|
-
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
async function setEngineEjs(app, options = constants_1.EJS_DEFAULTS) {
|
|
15
|
+
(0, resolve_render_1.packageResolver)("ejs");
|
|
16
|
+
app.set("view engine", options.viewEngine || constants_1.EJS_DEFAULTS.viewEngine);
|
|
17
|
+
app.set("views", options.viewsDir || constants_1.EJS_DEFAULTS.viewsDir);
|
|
18
|
+
if (Array.isArray(options.viewsDir)) {
|
|
19
|
+
options.viewsDir.forEach((dir) => {
|
|
20
|
+
app.set("views", dir);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (options.serverOptions) {
|
|
24
|
+
app.locals = {
|
|
25
|
+
...app.locals,
|
|
26
|
+
...options.serverOptions,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Set Handlebars as the view engine
|
|
32
|
+
* @param {express.Application} app - The express application
|
|
33
|
+
* @param {HandlebarsOptions} [options=HANDLEBARS_DEFAULTS] - The handlebars options
|
|
34
|
+
*/
|
|
35
|
+
async function setEngineHandlebars(app, options = constants_1.HANDLEBARS_DEFAULTS) {
|
|
36
|
+
const logger = new core_1.Logger();
|
|
37
|
+
try {
|
|
38
|
+
const hbs = (0, resolve_render_1.packageResolver)("hbs");
|
|
39
|
+
hbs.registerPartials(options.partialsDir || constants_1.DEFAULT_PARTIALS_DIR);
|
|
40
|
+
app.set("view engine", options.viewEngine || constants_1.HANDLEBARS_DEFAULTS.viewEngine);
|
|
41
|
+
app.set("views", options.viewsDir || constants_1.HANDLEBARS_DEFAULTS.viewsDir);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
logger.error(error.message, "handlebars-config");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set Pug as the view engine
|
|
49
|
+
* @param {express.Application} app - The express application
|
|
50
|
+
* @param {PugOptions} [options=PUG_DEFAULTS] - The pug options
|
|
51
|
+
*/
|
|
52
|
+
async function setEnginePug(app, options = constants_1.PUG_DEFAULTS) {
|
|
53
|
+
(0, resolve_render_1.packageResolver)("pug");
|
|
54
|
+
app.set("view engine", options.viewEngine || constants_1.PUG_DEFAULTS.viewEngine);
|
|
55
|
+
app.set("views", options.viewsDir || constants_1.PUG_DEFAULTS.viewsDir);
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FactoryType = void 0;
|
|
5
|
+
var FactoryType;
|
|
6
|
+
(function (FactoryType) {
|
|
7
|
+
FactoryType["DynamicValue"] = "toDynamicValue";
|
|
8
|
+
FactoryType["Factory"] = "toFactory";
|
|
9
|
+
FactoryType["Provider"] = "toProvider";
|
|
10
|
+
})(FactoryType || (exports.FactoryType = FactoryType = {}));
|
|
@@ -19,6 +19,17 @@
|
|
|
19
19
|
* @abstract
|
|
20
20
|
*/
|
|
21
21
|
export declare abstract class ApplicationBase {
|
|
22
|
+
/**
|
|
23
|
+
* Implement this method to set up global configurations for the server.
|
|
24
|
+
* This method is called before any other server initialization methods.
|
|
25
|
+
* Use this method to configure global settings that apply to the entire
|
|
26
|
+
* server application. Supports asynchronous setup with a Promise.
|
|
27
|
+
*
|
|
28
|
+
* @abstract
|
|
29
|
+
* @returns {void | Promise<void>}
|
|
30
|
+
* @public API
|
|
31
|
+
*/
|
|
32
|
+
protected abstract globalConfiguration(): void | Promise<void>;
|
|
22
33
|
/**
|
|
23
34
|
* Implement this method to set up required services or configurations before
|
|
24
35
|
* the server starts. This is essential for initializing dependencies or settings
|
|
@@ -26,6 +37,7 @@ export declare abstract class ApplicationBase {
|
|
|
26
37
|
*
|
|
27
38
|
* @abstract
|
|
28
39
|
* @returns {void | Promise<void>}
|
|
40
|
+
* @public API
|
|
29
41
|
*/
|
|
30
42
|
protected abstract configureServices(): void | Promise<void>;
|
|
31
43
|
/**
|
|
@@ -35,6 +47,7 @@ export declare abstract class ApplicationBase {
|
|
|
35
47
|
*
|
|
36
48
|
* @abstract
|
|
37
49
|
* @returns {void | Promise<void>}
|
|
50
|
+
* @public API
|
|
38
51
|
*/
|
|
39
52
|
protected abstract postServerInitialization(): void | Promise<void>;
|
|
40
53
|
/**
|
|
@@ -42,6 +55,10 @@ export declare abstract class ApplicationBase {
|
|
|
42
55
|
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
43
56
|
* cleanup procedures to ensure a graceful server shutdown. Supports asynchronous
|
|
44
57
|
* cleanup with a Promise.
|
|
58
|
+
*
|
|
59
|
+
* @abstract
|
|
60
|
+
* @returns {void | Promise<void>}
|
|
61
|
+
* @public API
|
|
45
62
|
*/
|
|
46
63
|
protected abstract serverShutdown(): void | Promise<void>;
|
|
47
64
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { IApplicationMessageToConsole } from "@expressots/core";
|
|
2
1
|
import express from "express";
|
|
3
|
-
import {
|
|
2
|
+
import { AppContainer, IConsoleMessage, ProviderManager, IMiddleware } from "@expressots/core";
|
|
3
|
+
import { RenderEngine, Env, Server } from "@expressots/shared";
|
|
4
|
+
import { interfaces } from "../di/di.interfaces";
|
|
4
5
|
import { ApplicationBase } from "./application-express.base";
|
|
5
|
-
import { IWebServer, ServerEnvironment } from "./application-express.types";
|
|
6
|
-
import { Engine, EngineOptions } from "./render/engine";
|
|
7
6
|
/**
|
|
8
7
|
* The AppExpress class provides methods for configuring and running an Express application.
|
|
9
8
|
* @class AppExpress
|
|
@@ -15,16 +14,20 @@ import { Engine, EngineOptions } from "./render/engine";
|
|
|
15
14
|
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
16
15
|
* @method isDevelopment - Verifies if the current environment is development.
|
|
17
16
|
*/
|
|
18
|
-
declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
17
|
+
export declare class AppExpress extends ApplicationBase implements Server.IWebServer {
|
|
19
18
|
private logger;
|
|
19
|
+
private console;
|
|
20
20
|
private app;
|
|
21
21
|
private port;
|
|
22
|
-
private environment
|
|
23
|
-
private
|
|
22
|
+
private environment?;
|
|
23
|
+
private appContainer;
|
|
24
24
|
private globalPrefix;
|
|
25
|
+
private middlewareManager;
|
|
25
26
|
private middlewares;
|
|
26
|
-
private
|
|
27
|
+
private providerManager;
|
|
27
28
|
private renderOptions;
|
|
29
|
+
constructor();
|
|
30
|
+
protected globalConfiguration(): void | Promise<void>;
|
|
28
31
|
protected configureServices(): void | Promise<void>;
|
|
29
32
|
protected postServerInitialization(): void | Promise<void>;
|
|
30
33
|
protected serverShutdown(): void | Promise<void>;
|
|
@@ -33,10 +36,29 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
|
33
36
|
*/
|
|
34
37
|
private handleExit;
|
|
35
38
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
39
|
+
* Initialize the InversifyJS container with the provided modules and options.
|
|
40
|
+
* @param appModules - An array of application modules to be loaded into the container.
|
|
41
|
+
* @param containerOptions - Container global configuration options.
|
|
42
|
+
* @option skipBaseClassChecks - Skip the base class checks for the container.
|
|
43
|
+
* @option autoBindInjectable - Automatically bind the injectable classes.
|
|
44
|
+
* @option defaultScope - The default scope to use for bindings.
|
|
45
|
+
*
|
|
46
|
+
* @returns The configured AppContainer instance.
|
|
47
|
+
* @public API
|
|
48
|
+
*/
|
|
49
|
+
configContainer(appModules: Array<interfaces.ContainerModule>, containerOptions?: interfaces.ContainerOptions): AppContainer;
|
|
50
|
+
/**
|
|
51
|
+
* Get the ProviderManager instance.
|
|
52
|
+
* @returns The ProviderManager instance.
|
|
53
|
+
* @public API
|
|
54
|
+
*/
|
|
55
|
+
get Provider(): ProviderManager;
|
|
56
|
+
/**
|
|
57
|
+
* Get the Middleware instance.
|
|
58
|
+
* @returns The Middleware instance.
|
|
59
|
+
* @public API
|
|
38
60
|
*/
|
|
39
|
-
|
|
61
|
+
get Middleware(): IMiddleware;
|
|
40
62
|
/**
|
|
41
63
|
* Configures the Express application with the provided middleware entries.
|
|
42
64
|
* @param app - The Express application instance.
|
|
@@ -53,18 +75,15 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
|
53
75
|
/**
|
|
54
76
|
* Start listening on the given port and environment.
|
|
55
77
|
* @param port - The port number to listen on.
|
|
56
|
-
* @param
|
|
57
|
-
* @
|
|
78
|
+
* @param appInfo - Optional message to display the app name and version.
|
|
79
|
+
* @public API
|
|
58
80
|
*/
|
|
59
|
-
listen(port: number
|
|
81
|
+
listen(port: number | string, appInfo?: IConsoleMessage): Promise<void>;
|
|
60
82
|
/**
|
|
61
83
|
* Sets the global route prefix for the application.
|
|
62
|
-
*
|
|
63
|
-
* @public
|
|
64
84
|
* @method setGlobalRoutePrefix
|
|
65
|
-
*
|
|
66
85
|
* @param {string} prefix - The prefix to use for all routes.
|
|
67
|
-
*
|
|
86
|
+
* @public API
|
|
68
87
|
*/
|
|
69
88
|
setGlobalRoutePrefix(prefix: string): void;
|
|
70
89
|
/**
|
|
@@ -73,25 +92,41 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
|
73
92
|
private configEngine;
|
|
74
93
|
/**
|
|
75
94
|
* Configures the application's view engine based on the provided configuration options.
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
78
95
|
* @method setEngine
|
|
79
96
|
* @template T - A generic type extending from RenderTemplateOptions.
|
|
80
97
|
*
|
|
81
98
|
* @param {Engine} engine - The view engine to set
|
|
82
99
|
* @param {EngineOptions} [options] - The configuration options for the view engine
|
|
100
|
+
* @public API
|
|
83
101
|
*/
|
|
84
|
-
setEngine<T extends EngineOptions>(engine: Engine, options?: T): Promise<void>;
|
|
102
|
+
setEngine<T extends RenderEngine.EngineOptions>(engine: RenderEngine.Engine, options?: T): Promise<void>;
|
|
85
103
|
/**
|
|
86
104
|
* Verifies if the current environment is development.
|
|
87
|
-
*
|
|
88
105
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
106
|
+
* @public API
|
|
89
107
|
*/
|
|
90
108
|
protected isDevelopment(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Load environment variables from the specified file based on the environment configuration.
|
|
111
|
+
* @param environment - The environment to load configuration for.
|
|
112
|
+
* @param options - The options to use for loading the environment configuration.
|
|
113
|
+
* @option env - The environment configuration options.
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* {
|
|
117
|
+
env: {
|
|
118
|
+
development: ".env.development",
|
|
119
|
+
production: ".env.production"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
* ```
|
|
123
|
+
* @public API
|
|
124
|
+
*/
|
|
125
|
+
initEnvironment(environment: Env.Environment, options?: Env.IEnvironment): void;
|
|
91
126
|
/**
|
|
92
127
|
* Get the underlying HTTP server. (default: Express.js)
|
|
93
128
|
* @returns The underlying HTTP server after initialization.
|
|
129
|
+
* @public API
|
|
94
130
|
*/
|
|
95
131
|
getHttpServer(): Promise<express.Application>;
|
|
96
132
|
}
|
|
97
|
-
export { AppExpress };
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import express
|
|
2
|
-
import { IApplicationMessageToConsole } from "@expressots/core";
|
|
3
|
-
import { Container } from "inversify";
|
|
4
|
-
import { Engine, EngineOptions } from "./render/engine";
|
|
5
|
-
/**
|
|
6
|
-
* Interface for the WebServer application implementation.
|
|
7
|
-
*/
|
|
8
|
-
export interface IWebServer {
|
|
9
|
-
configure(container: Container): Promise<void>;
|
|
10
|
-
listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
|
|
11
|
-
setEngine<T extends EngineOptions>(engine: Engine, options?: T): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Constructor type for IWebServer.
|
|
15
|
-
*/
|
|
16
|
-
export interface IWebServerConstructor<T extends IWebServer> {
|
|
17
|
-
new (): T;
|
|
18
|
-
}
|
|
1
|
+
import express from "express";
|
|
19
2
|
/**
|
|
20
3
|
* ExpressHandler Type
|
|
21
4
|
*
|
|
@@ -38,26 +21,3 @@ export type MiddlewareConfig = {
|
|
|
38
21
|
path?: string;
|
|
39
22
|
middlewares: Array<ExpressHandler>;
|
|
40
23
|
};
|
|
41
|
-
/**
|
|
42
|
-
* Expresso middleware interface.
|
|
43
|
-
*/
|
|
44
|
-
interface IExpressoMiddleware {
|
|
45
|
-
use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Abstract class for creating custom Expresso middleware.
|
|
49
|
-
* Custom middleware classes should extend this class and implement the use method.
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
export declare abstract class ExpressoMiddleware implements IExpressoMiddleware {
|
|
53
|
-
get name(): string;
|
|
54
|
-
abstract use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Enum representing possible server environments.
|
|
58
|
-
*/
|
|
59
|
-
export declare enum ServerEnvironment {
|
|
60
|
-
Development = "development",
|
|
61
|
-
Production = "production"
|
|
62
|
-
}
|
|
63
|
-
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
-
import { interfaces as inversifyInterfaces } from "
|
|
2
|
+
import { interfaces as inversifyInterfaces } from "../../di/di.interfaces";
|
|
3
3
|
import type { HttpContext } from "./interfaces";
|
|
4
4
|
export declare abstract class BaseMiddleware implements BaseMiddleware {
|
|
5
5
|
httpContext: HttpContext;
|
|
@@ -40,5 +40,5 @@ export declare enum HTTP_VERBS_ENUM {
|
|
|
40
40
|
trace = "TRACE"
|
|
41
41
|
}
|
|
42
42
|
export declare const DUPLICATED_CONTROLLER_NAME: (name: string) => string;
|
|
43
|
-
export declare const NO_CONTROLLERS_FOUND
|
|
43
|
+
export declare const NO_CONTROLLERS_FOUND = "No controller found! Please ensure that you have register at least one Controller.";
|
|
44
44
|
export declare const DEFAULT_ROUTING_ROOT_PATH = "/";
|