@adonisjs/http-server 5.12.0 → 6.0.1-0
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/README.md +15 -38
- package/build/index.d.ts +16 -0
- package/build/index.js +16 -0
- package/build/src/cookies/client.d.ts +12 -0
- package/build/src/cookies/client.js +42 -0
- package/build/src/cookies/drivers/encrypted.d.ts +4 -0
- package/build/src/cookies/drivers/encrypted.js +16 -0
- package/build/src/cookies/drivers/plain.d.ts +3 -0
- package/build/src/cookies/drivers/plain.js +13 -0
- package/build/src/cookies/drivers/signed.d.ts +4 -0
- package/build/src/cookies/drivers/signed.js +16 -0
- package/build/src/cookies/parser.d.ts +9 -0
- package/build/src/cookies/parser.js +69 -0
- package/build/src/cookies/serializer.d.ts +11 -0
- package/build/src/cookies/serializer.js +39 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +2 -0
- package/build/src/define_config.d.ts +2 -0
- package/build/src/define_config.js +40 -0
- package/build/src/define_middleware.d.ts +4 -0
- package/build/src/define_middleware.js +6 -0
- package/build/src/exceptions/abort_exception.d.ts +5 -0
- package/build/src/exceptions/abort_exception.js +6 -0
- package/build/src/exceptions/cannot_lookup_route.d.ts +5 -0
- package/build/src/exceptions/cannot_lookup_route.js +5 -0
- package/build/src/exceptions/http_exception.d.ts +6 -0
- package/build/src/exceptions/http_exception.js +20 -0
- package/build/src/exceptions/route_not_found.d.ts +5 -0
- package/build/src/exceptions/route_not_found.js +5 -0
- package/build/src/helpers.d.ts +6 -67
- package/build/src/helpers.js +13 -168
- package/build/src/http_context/local_storage.d.ts +9 -0
- package/build/src/http_context/local_storage.js +14 -0
- package/build/src/http_context/main.d.ts +20 -0
- package/build/src/http_context/main.js +49 -0
- package/build/src/middleware/store.d.ts +11 -0
- package/build/src/middleware/store.js +33 -0
- package/build/src/qs.d.ts +7 -0
- package/build/src/qs.js +13 -0
- package/build/src/redirect.d.ts +18 -0
- package/build/src/redirect.js +80 -0
- package/build/src/request.d.ts +81 -0
- package/build/src/request.js +315 -0
- package/build/src/response.d.ts +108 -0
- package/build/src/response.js +587 -0
- package/build/src/router/brisk.d.ts +18 -0
- package/build/src/router/brisk.js +35 -0
- package/build/src/router/executor.d.ts +4 -0
- package/build/src/router/executor.js +16 -0
- package/build/src/router/group.d.ts +19 -0
- package/build/src/router/group.js +117 -0
- package/build/src/router/lookup_store/main.d.ts +17 -0
- package/build/src/router/lookup_store/main.js +37 -0
- package/build/src/router/lookup_store/route_finder.d.ts +8 -0
- package/build/src/router/lookup_store/route_finder.js +28 -0
- package/build/src/router/lookup_store/url_builder.d.ts +16 -0
- package/build/src/router/lookup_store/url_builder.js +111 -0
- package/build/src/router/main.d.ts +36 -0
- package/build/src/router/main.js +161 -0
- package/build/src/router/matchers.d.ts +14 -0
- package/build/src/router/matchers.js +15 -0
- package/build/src/router/resource.d.ts +27 -0
- package/build/src/router/resource.js +124 -0
- package/build/src/router/route.d.ts +28 -0
- package/build/src/router/route.js +135 -0
- package/build/src/router/store.d.ts +12 -0
- package/build/src/router/store.js +87 -0
- package/build/src/server/factories/final_handler.d.ts +4 -0
- package/build/src/server/factories/final_handler.js +17 -0
- package/build/src/server/factories/middleware_handler.d.ts +5 -0
- package/build/src/server/factories/middleware_handler.js +5 -0
- package/build/src/server/factories/use_return_value.d.ts +2 -0
- package/build/src/server/factories/use_return_value.js +9 -0
- package/build/src/server/factories/write_response.d.ts +2 -0
- package/build/src/server/factories/write_response.js +12 -0
- package/build/src/server/main.d.ts +23 -0
- package/build/src/server/main.js +124 -0
- package/build/src/types/base.d.ts +5 -0
- package/build/src/types/base.js +1 -0
- package/build/src/types/main.d.ts +7 -0
- package/build/src/types/main.js +7 -0
- package/build/src/types/middleware.d.ts +14 -0
- package/build/src/types/middleware.js +1 -0
- package/build/src/types/qs.d.ts +15 -0
- package/build/src/types/qs.js +1 -0
- package/build/src/types/request.d.ts +7 -0
- package/build/src/types/request.js +1 -0
- package/build/src/types/response.d.ts +18 -0
- package/build/src/types/response.js +1 -0
- package/build/src/types/route.d.ts +74 -0
- package/build/src/types/route.js +1 -0
- package/build/src/types/server.d.ts +13 -0
- package/build/src/types/server.js +1 -0
- package/package.json +88 -86
- package/build/adonis-typings/container.d.ts +0 -24
- package/build/adonis-typings/container.js +0 -8
- package/build/adonis-typings/context.d.ts +0 -73
- package/build/adonis-typings/context.js +0 -8
- package/build/adonis-typings/cookie-client.d.ts +0 -34
- package/build/adonis-typings/cookie-client.js +0 -8
- package/build/adonis-typings/http-server.d.ts +0 -98
- package/build/adonis-typings/http-server.js +0 -8
- package/build/adonis-typings/index.d.ts +0 -16
- package/build/adonis-typings/index.js +0 -16
- package/build/adonis-typings/middleware.d.ts +0 -95
- package/build/adonis-typings/middleware.js +0 -8
- package/build/adonis-typings/request.d.ts +0 -556
- package/build/adonis-typings/request.js +0 -8
- package/build/adonis-typings/response.d.ts +0 -440
- package/build/adonis-typings/response.js +0 -8
- package/build/adonis-typings/route.d.ts +0 -559
- package/build/adonis-typings/route.js +0 -8
- package/build/exceptions.json +0 -110
- package/build/providers/HttpServerProvider.d.ts +0 -46
- package/build/providers/HttpServerProvider.js +0 -100
- package/build/src/Cookie/Client/index.d.ts +0 -39
- package/build/src/Cookie/Client/index.js +0 -108
- package/build/src/Cookie/Drivers/Encrypted.d.ts +0 -24
- package/build/src/Cookie/Drivers/Encrypted.js +0 -42
- package/build/src/Cookie/Drivers/Plain.d.ts +0 -23
- package/build/src/Cookie/Drivers/Plain.js +0 -40
- package/build/src/Cookie/Drivers/Signed.d.ts +0 -24
- package/build/src/Cookie/Drivers/Signed.js +0 -42
- package/build/src/Cookie/Parser/index.d.ts +0 -61
- package/build/src/Cookie/Parser/index.js +0 -174
- package/build/src/Cookie/Serializer/index.d.ts +0 -46
- package/build/src/Cookie/Serializer/index.js +0 -88
- package/build/src/Exceptions/HttpException.d.ts +0 -20
- package/build/src/Exceptions/HttpException.js +0 -36
- package/build/src/Exceptions/RouterException.d.ts +0 -36
- package/build/src/Exceptions/RouterException.js +0 -76
- package/build/src/HttpContext/LocalStorage/index.d.ts +0 -24
- package/build/src/HttpContext/LocalStorage/index.js +0 -28
- package/build/src/HttpContext/index.d.ts +0 -90
- package/build/src/HttpContext/index.js +0 -181
- package/build/src/MiddlewareStore/index.d.ts +0 -92
- package/build/src/MiddlewareStore/index.js +0 -133
- package/build/src/Redirect/index.d.ts +0 -71
- package/build/src/Redirect/index.js +0 -139
- package/build/src/Request/index.d.ts +0 -619
- package/build/src/Request/index.js +0 -862
- package/build/src/Response/index.d.ts +0 -414
- package/build/src/Response/index.js +0 -1010
- package/build/src/Router/BriskRoute.d.ts +0 -53
- package/build/src/Router/BriskRoute.js +0 -74
- package/build/src/Router/Group.d.ts +0 -101
- package/build/src/Router/Group.js +0 -165
- package/build/src/Router/LookupStore.d.ts +0 -122
- package/build/src/Router/LookupStore.js +0 -264
- package/build/src/Router/Matchers.d.ts +0 -31
- package/build/src/Router/Matchers.js +0 -43
- package/build/src/Router/Resource.d.ts +0 -95
- package/build/src/Router/Resource.js +0 -182
- package/build/src/Router/Route.d.ts +0 -138
- package/build/src/Router/Route.js +0 -204
- package/build/src/Router/Store.d.ts +0 -93
- package/build/src/Router/Store.js +0 -211
- package/build/src/Router/index.d.ts +0 -142
- package/build/src/Router/index.js +0 -333
- package/build/src/Server/ExceptionManager/index.d.ts +0 -49
- package/build/src/Server/ExceptionManager/index.js +0 -96
- package/build/src/Server/Hooks/index.d.ts +0 -43
- package/build/src/Server/Hooks/index.js +0 -77
- package/build/src/Server/PreCompiler/index.d.ts +0 -60
- package/build/src/Server/PreCompiler/index.js +0 -143
- package/build/src/Server/RequestHandler/index.d.ts +0 -39
- package/build/src/Server/RequestHandler/index.js +0 -87
- package/build/src/Server/index.d.ts +0 -90
- package/build/src/Server/index.js +0 -175
- package/build/standalone.d.ts +0 -14
- package/build/standalone.js +0 -23
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Hooks = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Exposes to API to register and execute before and after hooks
|
|
14
|
-
*/
|
|
15
|
-
class Hooks {
|
|
16
|
-
constructor() {
|
|
17
|
-
/**
|
|
18
|
-
* Registered before and after hooks
|
|
19
|
-
*/
|
|
20
|
-
this.hooks = {
|
|
21
|
-
before: [],
|
|
22
|
-
after: [],
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Register before hook
|
|
27
|
-
*/
|
|
28
|
-
before(cb) {
|
|
29
|
-
this.hooks.before.push(cb);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Register after hook
|
|
34
|
-
*/
|
|
35
|
-
after(cb) {
|
|
36
|
-
this.hooks.after.push(cb);
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Executing before hooks in series. If this method returns `true`,
|
|
41
|
-
* it means that one of the before hooks wants to end the request
|
|
42
|
-
* without further processing it.
|
|
43
|
-
*/
|
|
44
|
-
async executeBefore(ctx) {
|
|
45
|
-
for (let hook of this.hooks.before) {
|
|
46
|
-
await hook(ctx);
|
|
47
|
-
/*
|
|
48
|
-
* We must break the loop when one of the hooks set the response
|
|
49
|
-
*/
|
|
50
|
-
if (ctx.response.hasLazyBody || !ctx.response.isPending) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Executes after hooks in series.
|
|
58
|
-
*/
|
|
59
|
-
async executeAfter(ctx) {
|
|
60
|
-
for (let hook of this.hooks.after) {
|
|
61
|
-
await hook(ctx);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* The commit action enables us to optimize the hook handlers
|
|
66
|
-
* for runtime peformance
|
|
67
|
-
*/
|
|
68
|
-
commit() {
|
|
69
|
-
if (this.hooks.before.length === 0) {
|
|
70
|
-
this.executeBefore = async () => false;
|
|
71
|
-
}
|
|
72
|
-
if (this.hooks.after.length === 0) {
|
|
73
|
-
this.executeAfter = async () => { };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.Hooks = Hooks;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference path="../../../adonis-typings/index.d.ts" />
|
|
10
|
-
import { RouteNode } from '@ioc:Adonis/Core/Route';
|
|
11
|
-
import { IocContract } from '@adonisjs/fold';
|
|
12
|
-
import { MiddlewareStoreContract } from '@ioc:Adonis/Core/Middleware';
|
|
13
|
-
/**
|
|
14
|
-
* Precompiler is used to pre compiler the route handler and middleware. We
|
|
15
|
-
* lookup the middleware and controllers upfront in the IoC container
|
|
16
|
-
* and cache the lookup to boost the runtime performance.
|
|
17
|
-
*
|
|
18
|
-
* Also each route gets a `finalHandler` property, which is used to invoke the
|
|
19
|
-
* route middleware and the route actual handler
|
|
20
|
-
*/
|
|
21
|
-
export declare class PreCompiler {
|
|
22
|
-
private middlewareStore;
|
|
23
|
-
/**
|
|
24
|
-
* This function is used by reference to execute the route handler
|
|
25
|
-
*/
|
|
26
|
-
private runRouteHandler;
|
|
27
|
-
/**
|
|
28
|
-
* Method to execute middleware using the middleware store
|
|
29
|
-
*/
|
|
30
|
-
private executeMiddleware;
|
|
31
|
-
/**
|
|
32
|
-
* This function is used by reference to execute the route middleware + route handler
|
|
33
|
-
*/
|
|
34
|
-
private runRouteMiddleware;
|
|
35
|
-
/**
|
|
36
|
-
* The resolver used to resolve the controllers from IoC container
|
|
37
|
-
*/
|
|
38
|
-
private resolver;
|
|
39
|
-
constructor(container: IocContract, middlewareStore: MiddlewareStoreContract);
|
|
40
|
-
/**
|
|
41
|
-
* Pre-compiling the handler to boost the runtime performance
|
|
42
|
-
*/
|
|
43
|
-
private compileHandler;
|
|
44
|
-
/**
|
|
45
|
-
* Pre-compile the route middleware to boost runtime performance
|
|
46
|
-
*/
|
|
47
|
-
private compileMiddleware;
|
|
48
|
-
/**
|
|
49
|
-
* Sets `finalHandler` property on the `route.meta`. This method
|
|
50
|
-
* can be invoked to execute route middleware stack + route
|
|
51
|
-
* controller/closure.
|
|
52
|
-
*/
|
|
53
|
-
private setFinalHandler;
|
|
54
|
-
/**
|
|
55
|
-
* Pre-compile route handler and it's middleware to boost runtime performance. Since
|
|
56
|
-
* most of this work is repetitive, we pre-compile and avoid doing it on every
|
|
57
|
-
* request
|
|
58
|
-
*/
|
|
59
|
-
compileRoute(route: RouteNode): void;
|
|
60
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.PreCompiler = void 0;
|
|
15
|
-
/// <reference path="../../../adonis-typings/index.ts" />
|
|
16
|
-
const haye_1 = __importDefault(require("haye"));
|
|
17
|
-
const co_compose_1 = require("co-compose");
|
|
18
|
-
const utils_1 = require("@poppinss/utils");
|
|
19
|
-
const helpers_1 = require("@poppinss/utils/build/helpers");
|
|
20
|
-
const helpers_2 = require("../../helpers");
|
|
21
|
-
const exceptions_json_1 = require("../../../exceptions.json");
|
|
22
|
-
/**
|
|
23
|
-
* Precompiler is used to pre compiler the route handler and middleware. We
|
|
24
|
-
* lookup the middleware and controllers upfront in the IoC container
|
|
25
|
-
* and cache the lookup to boost the runtime performance.
|
|
26
|
-
*
|
|
27
|
-
* Also each route gets a `finalHandler` property, which is used to invoke the
|
|
28
|
-
* route middleware and the route actual handler
|
|
29
|
-
*/
|
|
30
|
-
class PreCompiler {
|
|
31
|
-
constructor(container, middlewareStore) {
|
|
32
|
-
this.middlewareStore = middlewareStore;
|
|
33
|
-
/**
|
|
34
|
-
* This function is used by reference to execute the route handler
|
|
35
|
-
*/
|
|
36
|
-
this.runRouteHandler = async (ctx) => {
|
|
37
|
-
const routeHandler = ctx.route.meta.resolvedHandler;
|
|
38
|
-
/*
|
|
39
|
-
* Passing a child to the route handler, so that all internal
|
|
40
|
-
* actions can have their own child row
|
|
41
|
-
*/
|
|
42
|
-
let returnValue;
|
|
43
|
-
if (routeHandler.type === 'function') {
|
|
44
|
-
returnValue = await routeHandler.handler(ctx);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
returnValue = await this.resolver.call(routeHandler, undefined, (controller) => {
|
|
48
|
-
/**
|
|
49
|
-
* Allowing controller to provide the controller method argument
|
|
50
|
-
*/
|
|
51
|
-
if (typeof controller['getHandlerArguments'] === 'function') {
|
|
52
|
-
return controller['getHandlerArguments'](ctx);
|
|
53
|
-
}
|
|
54
|
-
return [ctx];
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
if ((0, helpers_2.useReturnValue)(returnValue, ctx)) {
|
|
58
|
-
ctx.response.send(returnValue);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Method to execute middleware using the middleware store
|
|
63
|
-
*/
|
|
64
|
-
this.executeMiddleware = (middleware, params) => {
|
|
65
|
-
return this.middlewareStore.invokeMiddleware(middleware, params);
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* This function is used by reference to execute the route middleware + route handler
|
|
69
|
-
*/
|
|
70
|
-
this.runRouteMiddleware = (ctx) => {
|
|
71
|
-
return new co_compose_1.Middleware()
|
|
72
|
-
.register(ctx.route.meta.resolvedMiddleware)
|
|
73
|
-
.runner()
|
|
74
|
-
.executor(this.executeMiddleware)
|
|
75
|
-
.finalHandler(this.runRouteHandler, [ctx])
|
|
76
|
-
.run([ctx]);
|
|
77
|
-
};
|
|
78
|
-
this.resolver = container.getResolver(undefined, 'httpControllers', 'App/Controllers/Http');
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Pre-compiling the handler to boost the runtime performance
|
|
82
|
-
*/
|
|
83
|
-
compileHandler(route) {
|
|
84
|
-
if (typeof route.handler === 'string') {
|
|
85
|
-
route.meta.resolvedHandler = this.resolver.resolve(route.handler, route.meta.namespace);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
route.meta.resolvedHandler = { type: 'function', handler: route.handler };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Pre-compile the route middleware to boost runtime performance
|
|
93
|
-
*/
|
|
94
|
-
compileMiddleware(route) {
|
|
95
|
-
route.meta.resolvedMiddleware = route.middleware.map((item) => {
|
|
96
|
-
if (typeof item === 'function') {
|
|
97
|
-
return { type: 'function', value: item, args: [] };
|
|
98
|
-
}
|
|
99
|
-
/*
|
|
100
|
-
* Extract middleware name and args from the string
|
|
101
|
-
*/
|
|
102
|
-
const [{ name, args }] = haye_1.default.fromPipe(item).toArray();
|
|
103
|
-
/*
|
|
104
|
-
* Get resolved node for the given name and raise exception when that
|
|
105
|
-
* name is missing
|
|
106
|
-
*/
|
|
107
|
-
const resolvedMiddleware = this.middlewareStore.getNamed(name);
|
|
108
|
-
if (!resolvedMiddleware) {
|
|
109
|
-
const error = new utils_1.Exception((0, helpers_1.interpolate)(exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.message, { name }), exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.status, exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.code);
|
|
110
|
-
error.help = exceptions_json_1.E_MISSING_NAMED_MIDDLEWARE.help.join('\n');
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
...resolvedMiddleware,
|
|
115
|
-
args,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Sets `finalHandler` property on the `route.meta`. This method
|
|
121
|
-
* can be invoked to execute route middleware stack + route
|
|
122
|
-
* controller/closure.
|
|
123
|
-
*/
|
|
124
|
-
setFinalHandler(route) {
|
|
125
|
-
if (route.meta.resolvedMiddleware && route.meta.resolvedMiddleware.length) {
|
|
126
|
-
route.meta.finalHandler = this.runRouteMiddleware;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
route.meta.finalHandler = this.runRouteHandler;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Pre-compile route handler and it's middleware to boost runtime performance. Since
|
|
134
|
-
* most of this work is repetitive, we pre-compile and avoid doing it on every
|
|
135
|
-
* request
|
|
136
|
-
*/
|
|
137
|
-
compileRoute(route) {
|
|
138
|
-
this.compileHandler(route);
|
|
139
|
-
this.compileMiddleware(route);
|
|
140
|
-
this.setFinalHandler(route);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.PreCompiler = PreCompiler;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference path="../../../adonis-typings/index.d.ts" />
|
|
10
|
-
import { RouterContract } from '@ioc:Adonis/Core/Route';
|
|
11
|
-
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
12
|
-
import { MiddlewareStoreContract } from '@ioc:Adonis/Core/Middleware';
|
|
13
|
-
/**
|
|
14
|
-
* Handles the request by invoking it's middleware chain, along with the
|
|
15
|
-
* route finalHandler
|
|
16
|
-
*/
|
|
17
|
-
export declare class RequestHandler {
|
|
18
|
-
private middlewareStore;
|
|
19
|
-
private router;
|
|
20
|
-
private globalMiddleware;
|
|
21
|
-
private handleRequest;
|
|
22
|
-
constructor(middlewareStore: MiddlewareStoreContract, router: RouterContract);
|
|
23
|
-
/**
|
|
24
|
-
* Function to invoke global middleware
|
|
25
|
-
*/
|
|
26
|
-
private executeMiddleware;
|
|
27
|
-
/**
|
|
28
|
-
* Finds the route for the request
|
|
29
|
-
*/
|
|
30
|
-
private findRoute;
|
|
31
|
-
/**
|
|
32
|
-
* Handles the request and invokes required middleware/handlers
|
|
33
|
-
*/
|
|
34
|
-
handle(ctx: HttpContextContract): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Computing certain methods to optimize for runtime performance
|
|
37
|
-
*/
|
|
38
|
-
commit(): void;
|
|
39
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.RequestHandler = void 0;
|
|
12
|
-
/// <reference path="../../../adonis-typings/index.ts" />
|
|
13
|
-
const co_compose_1 = require("co-compose");
|
|
14
|
-
const helpers_1 = require("@poppinss/utils/build/helpers");
|
|
15
|
-
const HttpException_1 = require("../../Exceptions/HttpException");
|
|
16
|
-
const exceptions_json_1 = require("../../../exceptions.json");
|
|
17
|
-
/**
|
|
18
|
-
* Handles the request by invoking it's middleware chain, along with the
|
|
19
|
-
* route finalHandler
|
|
20
|
-
*/
|
|
21
|
-
class RequestHandler {
|
|
22
|
-
constructor(middlewareStore, router) {
|
|
23
|
-
this.middlewareStore = middlewareStore;
|
|
24
|
-
this.router = router;
|
|
25
|
-
/**
|
|
26
|
-
* Function to invoke global middleware
|
|
27
|
-
*/
|
|
28
|
-
this.executeMiddleware = (middleware, params) => {
|
|
29
|
-
return this.middlewareStore.invokeMiddleware(middleware, params);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Finds the route for the request
|
|
34
|
-
*/
|
|
35
|
-
findRoute(ctx) {
|
|
36
|
-
const url = ctx.request.url();
|
|
37
|
-
const method = ctx.request.method();
|
|
38
|
-
const hostname = ctx.request.hostname();
|
|
39
|
-
/*
|
|
40
|
-
* Profiling `route.match` method
|
|
41
|
-
*/
|
|
42
|
-
const matchRoute = ctx.profiler.profile('http:route:match');
|
|
43
|
-
const route = this.router.match(url, method, hostname || undefined);
|
|
44
|
-
matchRoute.end();
|
|
45
|
-
/*
|
|
46
|
-
* Raise error when route is missing
|
|
47
|
-
*/
|
|
48
|
-
if (!route) {
|
|
49
|
-
throw HttpException_1.HttpException.invoke((0, helpers_1.interpolate)(exceptions_json_1.E_ROUTE_NOT_FOUND.message, { method, url }), exceptions_json_1.E_ROUTE_NOT_FOUND.status, exceptions_json_1.E_ROUTE_NOT_FOUND.code);
|
|
50
|
-
}
|
|
51
|
-
/*
|
|
52
|
-
* Attach `params`, `subdomains` and `route` when route is found. This
|
|
53
|
-
* information only exists on a given route
|
|
54
|
-
*/
|
|
55
|
-
ctx.params = route.params;
|
|
56
|
-
ctx.subdomains = route.subdomains;
|
|
57
|
-
ctx.route = route.route;
|
|
58
|
-
ctx.routeKey = route.routeKey;
|
|
59
|
-
ctx.request.updateParams(ctx.params);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Handles the request and invokes required middleware/handlers
|
|
63
|
-
*/
|
|
64
|
-
async handle(ctx) {
|
|
65
|
-
this.findRoute(ctx);
|
|
66
|
-
return this.handleRequest(ctx);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Computing certain methods to optimize for runtime performance
|
|
70
|
-
*/
|
|
71
|
-
commit() {
|
|
72
|
-
const middleware = this.middlewareStore.get();
|
|
73
|
-
if (!middleware.length) {
|
|
74
|
-
this.handleRequest = (ctx) => ctx.route.meta.finalHandler(ctx);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.globalMiddleware = new co_compose_1.Middleware().register(middleware);
|
|
78
|
-
this.handleRequest = (ctx) => {
|
|
79
|
-
return this.globalMiddleware
|
|
80
|
-
.runner()
|
|
81
|
-
.executor(this.executeMiddleware)
|
|
82
|
-
.finalHandler(ctx.route.meta.finalHandler, [ctx])
|
|
83
|
-
.run([ctx]);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.RequestHandler = RequestHandler;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference path="../../adonis-typings/index.d.ts" />
|
|
10
|
-
/// <reference types="node" />
|
|
11
|
-
/// <reference types="node" />
|
|
12
|
-
import { Server as HttpsServer } from 'https';
|
|
13
|
-
import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
|
|
14
|
-
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
|
15
|
-
import { IncomingMessage, ServerResponse, Server as HttpServer } from 'http';
|
|
16
|
-
import { ServerContract, ServerConfig, ErrorHandler } from '@ioc:Adonis/Core/Server';
|
|
17
|
-
import { Hooks } from './Hooks';
|
|
18
|
-
import { Router } from '../Router';
|
|
19
|
-
import { MiddlewareStore } from '../MiddlewareStore';
|
|
20
|
-
/**
|
|
21
|
-
* Server class handles the HTTP requests by using all Adonis micro modules.
|
|
22
|
-
*/
|
|
23
|
-
export declare class Server implements ServerContract {
|
|
24
|
-
private application;
|
|
25
|
-
private encryption;
|
|
26
|
-
private httpConfig;
|
|
27
|
-
/**
|
|
28
|
-
* The server itself doesn't create the http server instance. However, the consumer
|
|
29
|
-
* of this class can create one and set the instance for further reference. This
|
|
30
|
-
* is what ignitor does.
|
|
31
|
-
*/
|
|
32
|
-
instance?: HttpServer | HttpsServer;
|
|
33
|
-
/**
|
|
34
|
-
* The middleware store to register global and named middleware
|
|
35
|
-
*/
|
|
36
|
-
middleware: MiddlewareStore;
|
|
37
|
-
/**
|
|
38
|
-
* The route to register routes
|
|
39
|
-
*/
|
|
40
|
-
router: Router;
|
|
41
|
-
/**
|
|
42
|
-
* Server before/after hooks
|
|
43
|
-
*/
|
|
44
|
-
hooks: Hooks;
|
|
45
|
-
/**
|
|
46
|
-
* Precompiler to set the finalHandler for the route
|
|
47
|
-
*/
|
|
48
|
-
private precompiler;
|
|
49
|
-
/**
|
|
50
|
-
* Exception manager to handle exceptions
|
|
51
|
-
*/
|
|
52
|
-
private exception;
|
|
53
|
-
/**
|
|
54
|
-
* Request handler to handle request after route is found
|
|
55
|
-
*/
|
|
56
|
-
private requestHandler;
|
|
57
|
-
constructor(application: ApplicationContract, encryption: EncryptionContract, httpConfig: ServerConfig);
|
|
58
|
-
/**
|
|
59
|
-
* Handles HTTP request
|
|
60
|
-
*/
|
|
61
|
-
private runBeforeHooksAndHandler;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the profiler row
|
|
64
|
-
*/
|
|
65
|
-
private getProfilerRow;
|
|
66
|
-
/**
|
|
67
|
-
* Returns the context for the request
|
|
68
|
-
*/
|
|
69
|
-
private getContext;
|
|
70
|
-
/**
|
|
71
|
-
* Handle the request
|
|
72
|
-
*/
|
|
73
|
-
private handleRequest;
|
|
74
|
-
/**
|
|
75
|
-
* Define custom error handler to handler all errors
|
|
76
|
-
* occurred during HTTP request
|
|
77
|
-
*/
|
|
78
|
-
errorHandler(handler: ErrorHandler): this;
|
|
79
|
-
/**
|
|
80
|
-
* Optimizes internal handlers, based upon the existence of
|
|
81
|
-
* before handlers and global middleware. This helps in
|
|
82
|
-
* increasing throughput by 10%
|
|
83
|
-
*/
|
|
84
|
-
optimize(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Handles a given HTTP request. This method can be attached to any HTTP
|
|
87
|
-
* server
|
|
88
|
-
*/
|
|
89
|
-
handle(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
90
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @adonisjs/http-server
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.Server = void 0;
|
|
15
|
-
/// <reference path="../../adonis-typings/index.ts" />
|
|
16
|
-
const ms_1 = __importDefault(require("ms"));
|
|
17
|
-
const Hooks_1 = require("./Hooks");
|
|
18
|
-
const Router_1 = require("../Router");
|
|
19
|
-
const Request_1 = require("../Request");
|
|
20
|
-
const Response_1 = require("../Response");
|
|
21
|
-
const PreCompiler_1 = require("./PreCompiler");
|
|
22
|
-
const HttpContext_1 = require("../HttpContext");
|
|
23
|
-
const RequestHandler_1 = require("./RequestHandler");
|
|
24
|
-
const MiddlewareStore_1 = require("../MiddlewareStore");
|
|
25
|
-
const ExceptionManager_1 = require("./ExceptionManager");
|
|
26
|
-
const LocalStorage_1 = require("../HttpContext/LocalStorage");
|
|
27
|
-
/**
|
|
28
|
-
* Server class handles the HTTP requests by using all Adonis micro modules.
|
|
29
|
-
*/
|
|
30
|
-
class Server {
|
|
31
|
-
constructor(application, encryption, httpConfig) {
|
|
32
|
-
this.application = application;
|
|
33
|
-
this.encryption = encryption;
|
|
34
|
-
this.httpConfig = httpConfig;
|
|
35
|
-
/**
|
|
36
|
-
* The middleware store to register global and named middleware
|
|
37
|
-
*/
|
|
38
|
-
this.middleware = new MiddlewareStore_1.MiddlewareStore(this.application.container);
|
|
39
|
-
/**
|
|
40
|
-
* The route to register routes
|
|
41
|
-
*/
|
|
42
|
-
this.router = new Router_1.Router(this.encryption, (route) => this.precompiler.compileRoute(route));
|
|
43
|
-
/**
|
|
44
|
-
* Server before/after hooks
|
|
45
|
-
*/
|
|
46
|
-
this.hooks = new Hooks_1.Hooks();
|
|
47
|
-
/**
|
|
48
|
-
* Precompiler to set the finalHandler for the route
|
|
49
|
-
*/
|
|
50
|
-
this.precompiler = new PreCompiler_1.PreCompiler(this.application.container, this.middleware);
|
|
51
|
-
/**
|
|
52
|
-
* Exception manager to handle exceptions
|
|
53
|
-
*/
|
|
54
|
-
this.exception = new ExceptionManager_1.ExceptionManager(this.application.container);
|
|
55
|
-
/**
|
|
56
|
-
* Request handler to handle request after route is found
|
|
57
|
-
*/
|
|
58
|
-
this.requestHandler = new RequestHandler_1.RequestHandler(this.middleware, this.router);
|
|
59
|
-
/*
|
|
60
|
-
* Pre process config to convert max age string to seconds.
|
|
61
|
-
*/
|
|
62
|
-
if (httpConfig.cookie.maxAge && typeof httpConfig.cookie.maxAge === 'string') {
|
|
63
|
-
httpConfig.cookie.maxAge = (0, ms_1.default)(httpConfig.cookie.maxAge) / 1000;
|
|
64
|
-
}
|
|
65
|
-
(0, LocalStorage_1.useAsyncLocalStorage)(httpConfig.useAsyncLocalStorage || false);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Handles HTTP request
|
|
69
|
-
*/
|
|
70
|
-
async runBeforeHooksAndHandler(ctx) {
|
|
71
|
-
/*
|
|
72
|
-
* Start with before hooks upfront. If they raise error
|
|
73
|
-
* then execute error handler.
|
|
74
|
-
*/
|
|
75
|
-
return this.hooks.executeBefore(ctx).then((shortcircuit) => {
|
|
76
|
-
if (!shortcircuit) {
|
|
77
|
-
return this.requestHandler.handle(ctx);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Returns the profiler row
|
|
83
|
-
*/
|
|
84
|
-
getProfilerRow(request) {
|
|
85
|
-
return this.application.profiler.create('http:request', {
|
|
86
|
-
request_id: request.id(),
|
|
87
|
-
url: request.url(),
|
|
88
|
-
method: request.method(),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the context for the request
|
|
93
|
-
*/
|
|
94
|
-
getContext(request, response, profilerRow) {
|
|
95
|
-
return new HttpContext_1.HttpContext(request, response, this.application.logger.child({
|
|
96
|
-
request_id: request.id(),
|
|
97
|
-
}), profilerRow);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Handle the request
|
|
101
|
-
*/
|
|
102
|
-
async handleRequest(ctx, requestAction, res) {
|
|
103
|
-
/*
|
|
104
|
-
* Handle request by executing hooks, request middleware stack
|
|
105
|
-
* and route handler
|
|
106
|
-
*/
|
|
107
|
-
try {
|
|
108
|
-
await this.runBeforeHooksAndHandler(ctx);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
await this.exception.handle(error, ctx);
|
|
112
|
-
}
|
|
113
|
-
/*
|
|
114
|
-
* Excute hooks when there are one or more hooks. The `ctx.response.finish`
|
|
115
|
-
* is intentionally inside both the `try` and `catch` blocks as a defensive
|
|
116
|
-
* measure.
|
|
117
|
-
*
|
|
118
|
-
* When we call `response.finish`, it will serialize the response body and may
|
|
119
|
-
* encouter errors while doing so and hence will be catched by the catch
|
|
120
|
-
* block.
|
|
121
|
-
*/
|
|
122
|
-
try {
|
|
123
|
-
await this.hooks.executeAfter(ctx);
|
|
124
|
-
requestAction.end({ status_code: res.statusCode });
|
|
125
|
-
ctx.response.finish();
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
await this.exception.handle(error, ctx);
|
|
129
|
-
requestAction.end({ status_code: res.statusCode, error });
|
|
130
|
-
ctx.response.finish();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Define custom error handler to handler all errors
|
|
135
|
-
* occurred during HTTP request
|
|
136
|
-
*/
|
|
137
|
-
errorHandler(handler) {
|
|
138
|
-
this.exception.registerHandler(handler);
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Optimizes internal handlers, based upon the existence of
|
|
143
|
-
* before handlers and global middleware. This helps in
|
|
144
|
-
* increasing throughput by 10%
|
|
145
|
-
*/
|
|
146
|
-
optimize() {
|
|
147
|
-
this.router.commit();
|
|
148
|
-
this.hooks.commit();
|
|
149
|
-
this.requestHandler.commit();
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Handles a given HTTP request. This method can be attached to any HTTP
|
|
153
|
-
* server
|
|
154
|
-
*/
|
|
155
|
-
async handle(req, res) {
|
|
156
|
-
const request = new Request_1.Request(req, res, this.encryption, this.httpConfig);
|
|
157
|
-
const response = new Response_1.Response(req, res, this.encryption, this.httpConfig, this.router);
|
|
158
|
-
const requestAction = this.getProfilerRow(request);
|
|
159
|
-
const ctx = this.getContext(request, response, requestAction);
|
|
160
|
-
/*
|
|
161
|
-
* Reset accept header when `forceContentNegotiationTo` is defined
|
|
162
|
-
*/
|
|
163
|
-
const accept = this.httpConfig.forceContentNegotiationTo;
|
|
164
|
-
if (accept) {
|
|
165
|
-
req.headers['accept'] = typeof accept === 'function' ? accept(ctx) : accept;
|
|
166
|
-
}
|
|
167
|
-
if (LocalStorage_1.usingAsyncLocalStorage) {
|
|
168
|
-
return LocalStorage_1.httpContextLocalStorage.run(ctx, () => this.handleRequest(ctx, requestAction, res));
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
return this.handleRequest(ctx, requestAction, res);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
exports.Server = Server;
|
package/build/standalone.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
export { Router } from './src/Router';
|
|
10
|
-
export { Server } from './src/Server';
|
|
11
|
-
export { Request } from './src/Request';
|
|
12
|
-
export { Response } from './src/Response';
|
|
13
|
-
export { HttpContext } from './src/HttpContext';
|
|
14
|
-
export { MiddlewareStore } from './src/MiddlewareStore';
|