@hyperspan/framework 1.0.11 → 1.0.12
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/package.json +1 -1
- package/src/server.ts +14 -8
- package/src/types.ts +1 -1
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -202,9 +202,11 @@ export function createRoute(config: Partial<HS.RouteConfig> = {}): HS.Route {
|
|
|
202
202
|
/**
|
|
203
203
|
* Add a middleware function to this route (for all HTTP methods) (non-destructive)
|
|
204
204
|
*/
|
|
205
|
-
use(middleware: HS.MiddlewareFunction, opts:
|
|
206
|
-
if (opts
|
|
207
|
-
|
|
205
|
+
use(middleware: HS.MiddlewareFunction, opts: HS.MiddlewareMethodOptions = {}) {
|
|
206
|
+
if (opts?.methods) {
|
|
207
|
+
opts.methods.forEach(method => {
|
|
208
|
+
api._middleware[method].push(middleware);
|
|
209
|
+
});
|
|
208
210
|
} else {
|
|
209
211
|
api._middleware['*'].push(middleware);
|
|
210
212
|
}
|
|
@@ -214,9 +216,11 @@ export function createRoute(config: Partial<HS.RouteConfig> = {}): HS.Route {
|
|
|
214
216
|
* Set the complete middleware stack for this route (for all HTTP methods) (destructive)
|
|
215
217
|
* NOTE: This will override the middleware stack for this route
|
|
216
218
|
*/
|
|
217
|
-
middleware(middleware: Array<HS.MiddlewareFunction>, opts:
|
|
218
|
-
if (opts
|
|
219
|
-
|
|
219
|
+
middleware(middleware: Array<HS.MiddlewareFunction>, opts: HS.MiddlewareMethodOptions = {}) {
|
|
220
|
+
if (opts?.methods) {
|
|
221
|
+
opts.methods.forEach(method => {
|
|
222
|
+
api._middleware[method] = middleware;
|
|
223
|
+
});
|
|
220
224
|
} else {
|
|
221
225
|
api._middleware['*'] = middleware;
|
|
222
226
|
}
|
|
@@ -326,8 +330,10 @@ export async function createServer(config: HS.Config = {} as HS.Config): Promise
|
|
|
326
330
|
_routes: _routes,
|
|
327
331
|
_middleware: { GET: [], POST: [], PUT: [], PATCH: [], DELETE: [], HEAD: [], OPTIONS: [], '*': [] },
|
|
328
332
|
use(middleware: HS.MiddlewareFunction, opts?: HS.MiddlewareMethodOptions) {
|
|
329
|
-
if (opts?.
|
|
330
|
-
|
|
333
|
+
if (opts?.methods) {
|
|
334
|
+
opts.methods.forEach(method => {
|
|
335
|
+
api._middleware[method].push(middleware);
|
|
336
|
+
});
|
|
331
337
|
} else {
|
|
332
338
|
api._middleware['*'].push(middleware);
|
|
333
339
|
}
|
package/src/types.ts
CHANGED
|
@@ -135,7 +135,7 @@ export namespace Hyperspan {
|
|
|
135
135
|
) => Promise<Response> | Response;
|
|
136
136
|
export type MiddlewareMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | '*';
|
|
137
137
|
export type MiddlewareMethodOptions = {
|
|
138
|
-
|
|
138
|
+
methods?: Hyperspan.MiddlewareMethod[];
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
export interface Route {
|