@quatrain/api-server-express 1.1.8 → 1.1.10
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/adapters/ExpressAdapter.d.ts +1 -8
- package/dist/adapters/ExpressAdapter.d.ts.map +1 -0
- package/dist/adapters/ExpressAdapter.js +1 -9
- package/dist/adapters/ExpressAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +3 -3
- package/src/adapters/ExpressAdapter.ts +62 -0
|
@@ -16,14 +16,7 @@ export declare class ExpressAdapter implements ServerAdapter {
|
|
|
16
16
|
createRouter(path: string): ServerAdapter;
|
|
17
17
|
start(port: number, callback?: () => void): void;
|
|
18
18
|
getNativeInstance(): any;
|
|
19
|
-
/**
|
|
20
|
-
* Configures the server to serve static files from a specified folder.
|
|
21
|
-
* It also sets up a fallback route for SPA (Single Page Application) navigation,
|
|
22
|
-
* ensuring that non-API routes return the main index.html file.
|
|
23
|
-
*
|
|
24
|
-
* @param folderPath The absolute path to the directory containing static files (e.g. built frontend).
|
|
25
|
-
* @param apiPrefix The prefix used for API routes, which will be ignored by the SPA fallback. Defaults to '/api'.
|
|
26
|
-
*/
|
|
27
19
|
serveStatic(folderPath: string, apiPrefix?: string): void;
|
|
28
20
|
addEndpoint(handler: EndpointHandler, endpointRoot: string, options?: EndpointOptions): void;
|
|
29
21
|
}
|
|
22
|
+
//# sourceMappingURL=ExpressAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/ExpressAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,UAAU,EAA2B,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAMnI,qBAAa,cAAe,YAAW,aAAa;IAE9C,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,MAAM;gBADN,WAAW,GAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,MAAkB,EAC7D,MAAM,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO;IAkB9C,OAAO,CAAC,WAAW;IA6CnB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI;IAU5C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI;IAU7C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI;IAU5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI;IAS/C,GAAG,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAS1B,aAAa,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI;IAiD9C,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;IAYzC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAahD,iBAAiB,IAAI,GAAG;IAYxB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,GAAE,MAAe,GAAG,IAAI;IAiBjE,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI;CAUlG"}
|
|
@@ -12,7 +12,6 @@ class ExpressAdapter {
|
|
|
12
12
|
this.appOrRouter = appOrRouter;
|
|
13
13
|
this.config = config;
|
|
14
14
|
if ('listen' in this.appOrRouter && typeof this.appOrRouter.listen === 'function') {
|
|
15
|
-
// Default global middlewares for top-level application
|
|
16
15
|
this.appOrRouter.disable('x-powered-by');
|
|
17
16
|
this.appOrRouter.use(express_1.default.json());
|
|
18
17
|
this.appOrRouter.use((req, res, next) => {
|
|
@@ -135,14 +134,6 @@ class ExpressAdapter {
|
|
|
135
134
|
getNativeInstance() {
|
|
136
135
|
return this.appOrRouter;
|
|
137
136
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Configures the server to serve static files from a specified folder.
|
|
140
|
-
* It also sets up a fallback route for SPA (Single Page Application) navigation,
|
|
141
|
-
* ensuring that non-API routes return the main index.html file.
|
|
142
|
-
*
|
|
143
|
-
* @param folderPath The absolute path to the directory containing static files (e.g. built frontend).
|
|
144
|
-
* @param apiPrefix The prefix used for API routes, which will be ignored by the SPA fallback. Defaults to '/api'.
|
|
145
|
-
*/
|
|
146
137
|
serveStatic(folderPath, apiPrefix = '/api') {
|
|
147
138
|
const path = require('node:path');
|
|
148
139
|
this.use(express_1.default.static(folderPath));
|
|
@@ -162,3 +153,4 @@ class ExpressAdapter {
|
|
|
162
153
|
}
|
|
163
154
|
}
|
|
164
155
|
exports.ExpressAdapter = ExpressAdapter;
|
|
156
|
+
//# sourceMappingURL=ExpressAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressAdapter.js","sourceRoot":"","sources":["../../src/adapters/ExpressAdapter.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAO7B,MAAa,cAAc;IAEb;IACA;IAFX,YACW,cAAoD,IAAA,iBAAO,GAAE,EAC7D,SAAiC,EAAE;QADnC,gBAAW,GAAX,WAAW,CAAkD;QAC7D,WAAM,GAAN,MAAM,CAA6B;QAE3C,IAAI,QAAQ,IAAI,IAAI,CAAC,WAAW,IAAI,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAEhF,IAAI,CAAC,WAAmC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YACjE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAA;YACpC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,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AC,CAAC,CAAC,YAAY,CAAA;QACjG,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAE1C,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzD,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QACtD,CAAC;QAED,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;CACH;AAnOD,wCAmOC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,3 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExpressAdapter = void 0;
|
|
4
4
|
var ExpressAdapter_1 = require("./adapters/ExpressAdapter");
|
|
5
5
|
Object.defineProperty(exports, "ExpressAdapter", { enumerable: true, get: function () { return ExpressAdapter_1.ExpressAdapter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAA0D;AAAjD,gHAAA,cAAc,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/api-server-express",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Express Adapter for Quatrain API Server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"typescript": "^5.2.2"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@quatrain/api": "^1.1.
|
|
33
|
-
"@quatrain/api-server": "^1.1.
|
|
32
|
+
"@quatrain/api": "^1.1.5",
|
|
33
|
+
"@quatrain/api-server": "^1.1.9",
|
|
34
34
|
"express": "^4.19.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import express from 'express'
|
|
2
2
|
import { ServerAdapter, ApiHandler, ApiRequest, ApiResponse, EndpointHandler, EndpointOptions, ApiMiddleware } from '@quatrain/api'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Api Server adapter wrapping the `express` framework.
|
|
6
|
+
* Maps Quatrain's standardized `ServerAdapter` interfaces to native Express mechanisms.
|
|
7
|
+
*/
|
|
4
8
|
export class ExpressAdapter implements ServerAdapter {
|
|
5
9
|
constructor(
|
|
6
10
|
private appOrRouter: express.Application | express.Router = express(),
|
|
@@ -61,26 +65,60 @@ export class ExpressAdapter implements ServerAdapter {
|
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Registers a GET endpoint.
|
|
70
|
+
*
|
|
71
|
+
* @param path - The URI path.
|
|
72
|
+
* @param handler - The standard Quatrain ApiHandler.
|
|
73
|
+
*/
|
|
64
74
|
get(path: string, handler: ApiHandler): void {
|
|
65
75
|
(this.appOrRouter as express.Router).get(path, this.wrapHandler(handler))
|
|
66
76
|
}
|
|
67
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Registers a POST endpoint.
|
|
80
|
+
*
|
|
81
|
+
* @param path - The URI path.
|
|
82
|
+
* @param handler - The standard Quatrain ApiHandler.
|
|
83
|
+
*/
|
|
68
84
|
post(path: string, handler: ApiHandler): void {
|
|
69
85
|
(this.appOrRouter as express.Router).post(path, this.wrapHandler(handler))
|
|
70
86
|
}
|
|
71
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Registers a PUT endpoint.
|
|
90
|
+
*
|
|
91
|
+
* @param path - The URI path.
|
|
92
|
+
* @param handler - The standard Quatrain ApiHandler.
|
|
93
|
+
*/
|
|
72
94
|
put(path: string, handler: ApiHandler): void {
|
|
73
95
|
(this.appOrRouter as express.Router).put(path, this.wrapHandler(handler))
|
|
74
96
|
}
|
|
75
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Registers a DELETE endpoint.
|
|
100
|
+
*
|
|
101
|
+
* @param path - The URI path.
|
|
102
|
+
* @param handler - The standard Quatrain ApiHandler.
|
|
103
|
+
*/
|
|
76
104
|
delete(path: string, handler: ApiHandler): void {
|
|
77
105
|
(this.appOrRouter as express.Router).delete(path, this.wrapHandler(handler))
|
|
78
106
|
}
|
|
79
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Attaches a native Express middleware or sub-router.
|
|
110
|
+
*
|
|
111
|
+
* @param middleware - The Express RequestHandler or Router.
|
|
112
|
+
*/
|
|
80
113
|
use(middleware: any): void {
|
|
81
114
|
(this.appOrRouter as express.Router).use(middleware)
|
|
82
115
|
}
|
|
83
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Injects a Quatrain-compatible API middleware into the flow.
|
|
119
|
+
*
|
|
120
|
+
* @param middleware - The Quatrain ApiMiddleware function.
|
|
121
|
+
*/
|
|
84
122
|
addMiddleware(middleware: ApiMiddleware): void {
|
|
85
123
|
const expressMiddleware = async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
86
124
|
const apiReq: ApiRequest = {
|
|
@@ -124,12 +162,24 @@ export class ExpressAdapter implements ServerAdapter {
|
|
|
124
162
|
(this.appOrRouter as express.Router).use(expressMiddleware)
|
|
125
163
|
}
|
|
126
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Spawns an isolated routing scope (sub-router).
|
|
167
|
+
*
|
|
168
|
+
* @param path - The prefix path for the router.
|
|
169
|
+
* @returns A new ExpressAdapter instance controlling the sub-router.
|
|
170
|
+
*/
|
|
127
171
|
createRouter(path: string): ServerAdapter {
|
|
128
172
|
const router = express.Router()
|
|
129
173
|
;(this.appOrRouter as express.Router).use(path, router)
|
|
130
174
|
return new ExpressAdapter(router)
|
|
131
175
|
}
|
|
132
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Binds the server to the network and starts listening.
|
|
179
|
+
*
|
|
180
|
+
* @param port - The network port.
|
|
181
|
+
* @param callback - Optional completion callback.
|
|
182
|
+
*/
|
|
133
183
|
start(port: number, callback?: () => void): void {
|
|
134
184
|
if ('listen' in this.appOrRouter && typeof this.appOrRouter.listen === 'function') {
|
|
135
185
|
this.appOrRouter.listen(port, callback)
|
|
@@ -138,6 +188,11 @@ export class ExpressAdapter implements ServerAdapter {
|
|
|
138
188
|
}
|
|
139
189
|
}
|
|
140
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves the underlying native framework instance.
|
|
193
|
+
*
|
|
194
|
+
* @returns The raw Express Application or Router instance.
|
|
195
|
+
*/
|
|
141
196
|
getNativeInstance(): any {
|
|
142
197
|
return this.appOrRouter
|
|
143
198
|
}
|
|
@@ -160,6 +215,13 @@ export class ExpressAdapter implements ServerAdapter {
|
|
|
160
215
|
})
|
|
161
216
|
}
|
|
162
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Composes and mounts a full EndpointHandler block at a specific root.
|
|
220
|
+
*
|
|
221
|
+
* @param handler - The endpoint initialization logic.
|
|
222
|
+
* @param endpointRoot - The base URI.
|
|
223
|
+
* @param options - Middlewares and operational options.
|
|
224
|
+
*/
|
|
163
225
|
addEndpoint(handler: EndpointHandler, endpointRoot: string, options: EndpointOptions = {}): void {
|
|
164
226
|
const fullPath = this.config.apiPrefix ? `${this.config.apiPrefix}${endpointRoot}` : endpointRoot
|
|
165
227
|
const router = this.createRouter(fullPath)
|