@dkx/http-server
Advanced tools
Comparing version 1.3.1 to 1.3.2
import { Request } from './request'; | ||
import { Response } from './response'; | ||
import { Middleware } from './middleware'; | ||
import { Middleware, RequestState } from './middleware'; | ||
export declare class MiddlewareStack { | ||
private readonly middlewares; | ||
constructor(middlewares: Array<Middleware>); | ||
run(request: Request, response: Response): Promise<Response>; | ||
run(request: Request, response: Response, state?: RequestState): Promise<Response>; | ||
private createNextFunction; | ||
} |
@@ -15,3 +15,3 @@ "use strict"; | ||
} | ||
run(request, response) { | ||
run(request, response, state = {}) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -21,3 +21,2 @@ if (!this.middlewares.length) { | ||
} | ||
const state = {}; | ||
const next = this.createNextFunction(request, state, 0); | ||
@@ -24,0 +23,0 @@ return yield this.middlewares[0](request, response, next, state); |
@@ -1,2 +0,2 @@ | ||
import { Middleware } from './middleware'; | ||
import { Middleware, RequestState } from './middleware'; | ||
import { Request } from './request'; | ||
@@ -10,4 +10,4 @@ import { Response } from './response'; | ||
run(port: number, fn?: () => void): void; | ||
middleware(req: Request, res: Response): Promise<Response>; | ||
middleware(req: Request, res: Response, state?: RequestState): Promise<Response>; | ||
close(fn?: () => void): void; | ||
} |
@@ -28,3 +28,3 @@ "use strict"; | ||
const req = request_1.transformFromNativeRequest(request); | ||
const res = yield this.middleware(req, new response_1.Response); | ||
const res = yield this.middleware(req, new response_1.Response, {}); | ||
response_1.transformToNativeResponse(response, res, () => { | ||
@@ -36,5 +36,5 @@ response.end(); | ||
} | ||
middleware(req, res) { | ||
middleware(req, res, state = {}) { | ||
const middlewares = new middleware_stack_1.MiddlewareStack([...this.middlewares]); | ||
return middlewares.run(req, res); | ||
return middlewares.run(req, res, state); | ||
} | ||
@@ -41,0 +41,0 @@ close(fn) { |
{ | ||
"name": "@dkx/http-server", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Minimalistic HTTP server", | ||
@@ -5,0 +5,0 @@ "repository": "git@gitlab.com:dkx/http/server.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33898
406