framework-do-dede 2.0.5 → 2.0.7
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/dist/dede.d.ts +3 -1
- package/dist/dede.js +9 -5
- package/dist/http/ElysiaHttpServer.d.ts +1 -0
- package/dist/http/ElysiaHttpServer.js +3 -0
- package/dist/http/ExpressHttpServer.d.ts +1 -0
- package/dist/http/ExpressHttpServer.js +3 -0
- package/dist/http/HttpServer.d.ts +1 -0
- package/package.json +1 -1
package/dist/dede.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export type Options = {
|
|
|
13
13
|
defaultServerError?: string;
|
|
14
14
|
};
|
|
15
15
|
export declare class Dede {
|
|
16
|
-
static
|
|
16
|
+
private static httpServer;
|
|
17
|
+
static init({ framework, registries, defaultServerError }: Options): Promise<Dede>;
|
|
18
|
+
static close(): Promise<void>;
|
|
17
19
|
private static clearControllers;
|
|
18
20
|
private static loadRegistries;
|
|
19
21
|
}
|
package/dist/dede.js
CHANGED
|
@@ -3,21 +3,25 @@ import { ControllerHandler } from "./handlers";
|
|
|
3
3
|
import { ElysiaHttpServer } from "./http/ElysiaHttpServer";
|
|
4
4
|
import { ExpressHttpServer } from "./http/ExpressHttpServer";
|
|
5
5
|
export class Dede {
|
|
6
|
+
static httpServer;
|
|
6
7
|
static async init({ framework, registries, defaultServerError }) {
|
|
7
8
|
await this.loadRegistries(registries);
|
|
8
|
-
let httpServer;
|
|
9
9
|
if (framework.use === 'elysia') {
|
|
10
|
-
httpServer = new ElysiaHttpServer(framework.middlewares || []);
|
|
10
|
+
Dede.httpServer = new ElysiaHttpServer(framework.middlewares || []);
|
|
11
11
|
}
|
|
12
12
|
if (framework.use === 'express') {
|
|
13
|
-
httpServer = new ExpressHttpServer(framework.middlewares || []);
|
|
13
|
+
Dede.httpServer = new ExpressHttpServer(framework.middlewares || []);
|
|
14
14
|
}
|
|
15
15
|
if (defaultServerError)
|
|
16
|
-
httpServer.setDefaultMessageError(defaultServerError);
|
|
16
|
+
Dede.httpServer.setDefaultMessageError(defaultServerError);
|
|
17
17
|
if (Registry.has('controllers')) {
|
|
18
|
-
new ControllerHandler(httpServer, framework.port || 80);
|
|
18
|
+
new ControllerHandler(Dede.httpServer, framework.port || 80);
|
|
19
19
|
this.clearControllers();
|
|
20
20
|
}
|
|
21
|
+
return Dede;
|
|
22
|
+
}
|
|
23
|
+
static async close() {
|
|
24
|
+
await Dede.httpServer.close();
|
|
21
25
|
}
|
|
22
26
|
static clearControllers() {
|
|
23
27
|
Registry.clear('controllers');
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import Elysia from "elysia";
|
|
3
3
|
import HttpServer from "./HttpServer";
|
|
4
4
|
export class ElysiaHttpServer extends HttpServer {
|
|
5
|
+
async close() {
|
|
6
|
+
await this.framework.stop();
|
|
7
|
+
}
|
|
5
8
|
constructor(uses) {
|
|
6
9
|
super(new Elysia(), 'elysia');
|
|
7
10
|
uses?.forEach(use => this.framework.use(use));
|
|
@@ -3,6 +3,9 @@ import express from "express";
|
|
|
3
3
|
import HttpServer from "./HttpServer";
|
|
4
4
|
const app = express();
|
|
5
5
|
export class ExpressHttpServer extends HttpServer {
|
|
6
|
+
async close() {
|
|
7
|
+
await this.framework.close();
|
|
8
|
+
}
|
|
6
9
|
constructor(uses) {
|
|
7
10
|
super(app, 'express');
|
|
8
11
|
this.framework.use(express.json());
|
|
@@ -26,6 +26,7 @@ export default abstract class HttpServer {
|
|
|
26
26
|
setDefaultMessageError(message: string): void;
|
|
27
27
|
getDefaultMessageError(): string | undefined;
|
|
28
28
|
listen(port: number): void;
|
|
29
|
+
abstract close(): Promise<void>;
|
|
29
30
|
private mountRoute;
|
|
30
31
|
private elysia;
|
|
31
32
|
private express;
|