@adonisjs/http-server 6.8.2-9 → 7.0.0-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/build/chunk-XX72ATFY.js +4388 -0
- package/build/factories/main.d.ts +149 -6
- package/build/factories/main.js +331 -14
- package/build/index.d.ts +272 -14
- package/build/index.js +308 -22
- package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
- package/build/main-e5b46c83.d.ts +2210 -0
- package/build/src/types/main.d.ts +14 -7
- package/build/src/types/main.js +0 -15
- package/package.json +62 -53
- package/build/factories/http_context.d.ts +0 -25
- package/build/factories/http_context.js +0 -51
- package/build/factories/http_server.d.ts +0 -8
- package/build/factories/http_server.js +0 -26
- package/build/factories/qs_parser_factory.d.ts +0 -20
- package/build/factories/qs_parser_factory.js +0 -44
- package/build/factories/request.d.ts +0 -29
- package/build/factories/request.js +0 -73
- package/build/factories/response.d.ts +0 -29
- package/build/factories/response.js +0 -77
- package/build/factories/router.d.ts +0 -23
- package/build/factories/router.js +0 -45
- package/build/factories/server_factory.d.ts +0 -29
- package/build/factories/server_factory.js +0 -65
- package/build/src/cookies/client.d.ts +0 -37
- package/build/src/cookies/client.js +0 -84
- package/build/src/cookies/drivers/encrypted.d.ts +0 -16
- package/build/src/cookies/drivers/encrypted.js +0 -36
- package/build/src/cookies/drivers/plain.d.ts +0 -15
- package/build/src/cookies/drivers/plain.js +0 -33
- package/build/src/cookies/drivers/signed.d.ts +0 -16
- package/build/src/cookies/drivers/signed.js +0 -36
- package/build/src/cookies/parser.d.ts +0 -37
- package/build/src/cookies/parser.js +0 -167
- package/build/src/cookies/serializer.d.ts +0 -33
- package/build/src/cookies/serializer.js +0 -79
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/define_config.d.ts +0 -5
- package/build/src/define_config.js +0 -51
- package/build/src/define_middleware.d.ts +0 -11
- package/build/src/define_middleware.js +0 -35
- package/build/src/exception_handler.d.ts +0 -112
- package/build/src/exception_handler.js +0 -303
- package/build/src/exceptions.d.ts +0 -84
- package/build/src/exceptions.js +0 -38
- package/build/src/helpers.d.ts +0 -23
- package/build/src/helpers.js +0 -84
- package/build/src/http_context/local_storage.d.ts +0 -12
- package/build/src/http_context/local_storage.js +0 -39
- package/build/src/http_context/main.d.ts +0 -58
- package/build/src/http_context/main.js +0 -105
- package/build/src/qs.d.ts +0 -11
- package/build/src/qs.js +0 -25
- package/build/src/redirect.d.ts +0 -42
- package/build/src/redirect.js +0 -140
- package/build/src/request.d.ts +0 -565
- package/build/src/request.js +0 -865
- package/build/src/response.d.ts +0 -540
- package/build/src/response.js +0 -1208
- package/build/src/router/brisk.d.ts +0 -42
- package/build/src/router/brisk.js +0 -85
- package/build/src/router/executor.d.ts +0 -8
- package/build/src/router/executor.js +0 -29
- package/build/src/router/factories/use_return_value.d.ts +0 -6
- package/build/src/router/factories/use_return_value.js +0 -22
- package/build/src/router/group.d.ts +0 -65
- package/build/src/router/group.js +0 -207
- package/build/src/router/lookup_store/main.d.ts +0 -49
- package/build/src/router/lookup_store/main.js +0 -86
- package/build/src/router/lookup_store/route_finder.d.ts +0 -21
- package/build/src/router/lookup_store/route_finder.js +0 -49
- package/build/src/router/lookup_store/url_builder.d.ts +0 -52
- package/build/src/router/lookup_store/url_builder.js +0 -209
- package/build/src/router/main.d.ts +0 -128
- package/build/src/router/main.js +0 -316
- package/build/src/router/matchers.d.ts +0 -27
- package/build/src/router/matchers.js +0 -36
- package/build/src/router/parser.d.ts +0 -5
- package/build/src/router/parser.js +0 -17
- package/build/src/router/resource.d.ts +0 -54
- package/build/src/router/resource.js +0 -216
- package/build/src/router/route.d.ts +0 -92
- package/build/src/router/route.js +0 -293
- package/build/src/router/store.d.ts +0 -66
- package/build/src/router/store.js +0 -195
- package/build/src/server/factories/final_handler.d.ts +0 -9
- package/build/src/server/factories/final_handler.js +0 -30
- package/build/src/server/factories/middleware_handler.d.ts +0 -8
- package/build/src/server/factories/middleware_handler.js +0 -16
- package/build/src/server/factories/write_response.d.ts +0 -6
- package/build/src/server/factories/write_response.js +0 -24
- package/build/src/server/main.js +0 -283
- package/build/src/types/base.d.ts +0 -19
- package/build/src/types/base.js +0 -9
- package/build/src/types/middleware.d.ts +0 -35
- package/build/src/types/middleware.js +0 -9
- package/build/src/types/qs.d.ts +0 -68
- package/build/src/types/qs.js +0 -9
- package/build/src/types/request.d.ts +0 -39
- package/build/src/types/request.js +0 -9
- package/build/src/types/response.d.ts +0 -45
- package/build/src/types/response.js +0 -9
- package/build/src/types/route.d.ts +0 -165
- package/build/src/types/route.js +0 -9
- package/build/src/types/server.d.ts +0 -72
- package/build/src/types/server.js +0 -9
package/build/src/exceptions.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { createError, Exception } from '@poppinss/utils';
|
|
10
|
-
export const E_ROUTE_NOT_FOUND = createError('Cannot %s:%s', 'E_ROUTE_NOT_FOUND', 404);
|
|
11
|
-
export const E_CANNOT_LOOKUP_ROUTE = createError('Cannot lookup route "%s"', 'E_CANNOT_LOOKUP_ROUTE', 500);
|
|
12
|
-
export const E_HTTP_EXCEPTION = class HttpException extends Exception {
|
|
13
|
-
body;
|
|
14
|
-
static code = 'E_HTTP_EXCEPTION';
|
|
15
|
-
/**
|
|
16
|
-
* This method returns an instance of the exception class
|
|
17
|
-
*/
|
|
18
|
-
static invoke(body, status, code = 'E_HTTP_EXCEPTION') {
|
|
19
|
-
if (body === null || body === undefined) {
|
|
20
|
-
const error = new this('HTTP Exception', { status, code });
|
|
21
|
-
error.body = 'Internal server error';
|
|
22
|
-
return error;
|
|
23
|
-
}
|
|
24
|
-
if (typeof body === 'object') {
|
|
25
|
-
const error = new this(body.message || 'HTTP Exception', { status, code });
|
|
26
|
-
error.body = body;
|
|
27
|
-
return error;
|
|
28
|
-
}
|
|
29
|
-
const error = new this(body, { status, code });
|
|
30
|
-
error.body = body;
|
|
31
|
-
return error;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export const E_HTTP_REQUEST_ABORTED = class AbortException extends E_HTTP_EXCEPTION {
|
|
35
|
-
handle(error, ctx) {
|
|
36
|
-
ctx.response.status(error.status).send(error.body);
|
|
37
|
-
}
|
|
38
|
-
};
|
package/build/src/helpers.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Route } from './router/route.js';
|
|
2
|
-
import { BriskRoute } from './router/brisk.js';
|
|
3
|
-
import { RouteGroup } from './router/group.js';
|
|
4
|
-
import type { RouteJSON } from './types/route.js';
|
|
5
|
-
import { RouteResource } from './router/resource.js';
|
|
6
|
-
/**
|
|
7
|
-
* Makes input string consistent by having only the starting
|
|
8
|
-
* slash
|
|
9
|
-
*/
|
|
10
|
-
export declare function dropSlash(input: string): string;
|
|
11
|
-
/**
|
|
12
|
-
* Returns a flat list of routes from the route groups and resources
|
|
13
|
-
*/
|
|
14
|
-
export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
|
|
15
|
-
/**
|
|
16
|
-
* Helper to know if the remote address should
|
|
17
|
-
* be trusted.
|
|
18
|
-
*/
|
|
19
|
-
export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Parses a range expression to an object filled with the range
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseRange<T>(range: string, value: T): Record<number, T>;
|
package/build/src/helpers.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import Cache from 'tmp-cache';
|
|
10
|
-
import { InvalidArgumentsException } from '@poppinss/utils';
|
|
11
|
-
import { BriskRoute } from './router/brisk.js';
|
|
12
|
-
import { RouteGroup } from './router/group.js';
|
|
13
|
-
import { RouteResource } from './router/resource.js';
|
|
14
|
-
const proxyCache = new Cache({ max: 200 });
|
|
15
|
-
/**
|
|
16
|
-
* Makes input string consistent by having only the starting
|
|
17
|
-
* slash
|
|
18
|
-
*/
|
|
19
|
-
export function dropSlash(input) {
|
|
20
|
-
if (input === '/') {
|
|
21
|
-
return '/';
|
|
22
|
-
}
|
|
23
|
-
return `/${input.replace(/^\//, '').replace(/\/$/, '')}`;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Returns a flat list of routes from the route groups and resources
|
|
27
|
-
*/
|
|
28
|
-
export function toRoutesJSON(routes) {
|
|
29
|
-
return routes.reduce((list, route) => {
|
|
30
|
-
if (route instanceof RouteGroup) {
|
|
31
|
-
list = list.concat(toRoutesJSON(route.routes));
|
|
32
|
-
return list;
|
|
33
|
-
}
|
|
34
|
-
if (route instanceof RouteResource) {
|
|
35
|
-
list = list.concat(toRoutesJSON(route.routes));
|
|
36
|
-
return list;
|
|
37
|
-
}
|
|
38
|
-
if (route instanceof BriskRoute) {
|
|
39
|
-
if (route.route && !route.route.isDeleted()) {
|
|
40
|
-
list.push(route.route.toJSON());
|
|
41
|
-
}
|
|
42
|
-
return list;
|
|
43
|
-
}
|
|
44
|
-
if (!route.isDeleted()) {
|
|
45
|
-
list.push(route.toJSON());
|
|
46
|
-
}
|
|
47
|
-
return list;
|
|
48
|
-
}, []);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Helper to know if the remote address should
|
|
52
|
-
* be trusted.
|
|
53
|
-
*/
|
|
54
|
-
export function trustProxy(remoteAddress, proxyFn) {
|
|
55
|
-
if (proxyCache.has(remoteAddress)) {
|
|
56
|
-
return proxyCache.get(remoteAddress);
|
|
57
|
-
}
|
|
58
|
-
const result = proxyFn(remoteAddress, 0);
|
|
59
|
-
proxyCache.set(remoteAddress, result);
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Parses a range expression to an object filled with the range
|
|
64
|
-
*/
|
|
65
|
-
export function parseRange(range, value) {
|
|
66
|
-
const parts = range.split('..');
|
|
67
|
-
const min = Number(parts[0]);
|
|
68
|
-
const max = Number(parts[1]);
|
|
69
|
-
if (Number.isNaN(min) || Number.isNaN(max)) {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
if (min === max) {
|
|
73
|
-
return {
|
|
74
|
-
[min]: value,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
if (max < min) {
|
|
78
|
-
throw new InvalidArgumentsException(`Invalid range "${range}"`);
|
|
79
|
-
}
|
|
80
|
-
return [...Array(max - min + 1).keys()].reduce((result, step) => {
|
|
81
|
-
result[min + step] = value;
|
|
82
|
-
return result;
|
|
83
|
-
}, {});
|
|
84
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
-
import type { HttpContext } from './main.js';
|
|
4
|
-
/**
|
|
5
|
-
* Async local storage for HTTP context
|
|
6
|
-
*/
|
|
7
|
-
export declare const asyncLocalStorage: {
|
|
8
|
-
isEnabled: boolean;
|
|
9
|
-
storage: null | AsyncLocalStorage<HttpContext>;
|
|
10
|
-
create(): AsyncLocalStorage<HttpContext>;
|
|
11
|
-
destroy(): void;
|
|
12
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
10
|
-
/**
|
|
11
|
-
* Async local storage for HTTP context
|
|
12
|
-
*/
|
|
13
|
-
export const asyncLocalStorage = {
|
|
14
|
-
/**
|
|
15
|
-
* Check if the async local storage for the HTTP
|
|
16
|
-
* context is enabled or not
|
|
17
|
-
*/
|
|
18
|
-
isEnabled: false,
|
|
19
|
-
/**
|
|
20
|
-
* HTTP context storage instance for the current scope
|
|
21
|
-
*/
|
|
22
|
-
storage: null,
|
|
23
|
-
/**
|
|
24
|
-
* Create the storage instance. This method must be called only
|
|
25
|
-
* once.
|
|
26
|
-
*/
|
|
27
|
-
create() {
|
|
28
|
-
this.isEnabled = true;
|
|
29
|
-
this.storage = new AsyncLocalStorage();
|
|
30
|
-
return this.storage;
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* Destroy the create storage instance
|
|
34
|
-
*/
|
|
35
|
-
destroy() {
|
|
36
|
-
this.isEnabled = false;
|
|
37
|
-
this.storage = null;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import Macroable from '@poppinss/macroable';
|
|
2
|
-
import type { Logger } from '@adonisjs/logger';
|
|
3
|
-
import { ContainerResolver } from '@adonisjs/fold';
|
|
4
|
-
import type { Request } from '../request.js';
|
|
5
|
-
import type { Response } from '../response.js';
|
|
6
|
-
import type { StoreRouteNode } from '../types/route.js';
|
|
7
|
-
/**
|
|
8
|
-
* Http context encapsulates properties for a given HTTP request. The
|
|
9
|
-
* context class can be extended using macros and getters.
|
|
10
|
-
*/
|
|
11
|
-
export declare class HttpContext extends Macroable {
|
|
12
|
-
request: Request;
|
|
13
|
-
response: Response;
|
|
14
|
-
logger: Logger;
|
|
15
|
-
containerResolver: ContainerResolver<any>;
|
|
16
|
-
/**
|
|
17
|
-
* Find if async localstorage is enabled for HTTP requests
|
|
18
|
-
* or not
|
|
19
|
-
*/
|
|
20
|
-
static get usingAsyncLocalStorage(): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Get access to the HTTP context. Available only when
|
|
23
|
-
* "usingAsyncLocalStorage" is true
|
|
24
|
-
*/
|
|
25
|
-
static get(): HttpContext | null;
|
|
26
|
-
/**
|
|
27
|
-
* Get the HttpContext instance or raise an exception if not
|
|
28
|
-
* available
|
|
29
|
-
*/
|
|
30
|
-
static getOrFail(): HttpContext;
|
|
31
|
-
/**
|
|
32
|
-
* Run a method that doesn't have access to HTTP context from
|
|
33
|
-
* the async local storage.
|
|
34
|
-
*/
|
|
35
|
-
static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
|
|
36
|
-
/**
|
|
37
|
-
* Reference to the current route. Not available inside
|
|
38
|
-
* server middleware
|
|
39
|
-
*/
|
|
40
|
-
route?: StoreRouteNode;
|
|
41
|
-
/**
|
|
42
|
-
* A unique key for the current route
|
|
43
|
-
*/
|
|
44
|
-
routeKey?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Route params
|
|
47
|
-
*/
|
|
48
|
-
params: Record<string, any>;
|
|
49
|
-
/**
|
|
50
|
-
* Route subdomains
|
|
51
|
-
*/
|
|
52
|
-
subdomains: Record<string, any>;
|
|
53
|
-
constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
|
|
54
|
-
/**
|
|
55
|
-
* A helper to see top level properties on the context object
|
|
56
|
-
*/
|
|
57
|
-
inspect(): string;
|
|
58
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { inspect } from 'node:util';
|
|
10
|
-
import Macroable from '@poppinss/macroable';
|
|
11
|
-
import { RuntimeException } from '@poppinss/utils';
|
|
12
|
-
import { asyncLocalStorage } from './local_storage.js';
|
|
13
|
-
/**
|
|
14
|
-
* Http context encapsulates properties for a given HTTP request. The
|
|
15
|
-
* context class can be extended using macros and getters.
|
|
16
|
-
*/
|
|
17
|
-
export class HttpContext extends Macroable {
|
|
18
|
-
request;
|
|
19
|
-
response;
|
|
20
|
-
logger;
|
|
21
|
-
containerResolver;
|
|
22
|
-
/**
|
|
23
|
-
* Find if async localstorage is enabled for HTTP requests
|
|
24
|
-
* or not
|
|
25
|
-
*/
|
|
26
|
-
static get usingAsyncLocalStorage() {
|
|
27
|
-
return asyncLocalStorage.isEnabled;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get access to the HTTP context. Available only when
|
|
31
|
-
* "usingAsyncLocalStorage" is true
|
|
32
|
-
*/
|
|
33
|
-
static get() {
|
|
34
|
-
if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
return asyncLocalStorage.storage.getStore() || null;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get the HttpContext instance or raise an exception if not
|
|
41
|
-
* available
|
|
42
|
-
*/
|
|
43
|
-
static getOrFail() {
|
|
44
|
-
/**
|
|
45
|
-
* Localstorage is not enabled
|
|
46
|
-
*/
|
|
47
|
-
if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
|
|
48
|
-
throw new RuntimeException('HTTP context is not available. Enable "useAsyncLocalStorage" inside "config/app.ts" file');
|
|
49
|
-
}
|
|
50
|
-
const store = this.get();
|
|
51
|
-
if (!store) {
|
|
52
|
-
throw new RuntimeException('Http context is not available outside of an HTTP request');
|
|
53
|
-
}
|
|
54
|
-
return store;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Run a method that doesn't have access to HTTP context from
|
|
58
|
-
* the async local storage.
|
|
59
|
-
*/
|
|
60
|
-
static runOutsideContext(callback, ...args) {
|
|
61
|
-
if (!asyncLocalStorage.storage) {
|
|
62
|
-
return callback(...args);
|
|
63
|
-
}
|
|
64
|
-
return asyncLocalStorage.storage.exit(callback, ...args);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Reference to the current route. Not available inside
|
|
68
|
-
* server middleware
|
|
69
|
-
*/
|
|
70
|
-
route;
|
|
71
|
-
/**
|
|
72
|
-
* A unique key for the current route
|
|
73
|
-
*/
|
|
74
|
-
routeKey;
|
|
75
|
-
/**
|
|
76
|
-
* Route params
|
|
77
|
-
*/
|
|
78
|
-
params = {};
|
|
79
|
-
/**
|
|
80
|
-
* Route subdomains
|
|
81
|
-
*/
|
|
82
|
-
subdomains = {};
|
|
83
|
-
constructor(request, response, logger, containerResolver) {
|
|
84
|
-
super();
|
|
85
|
-
this.request = request;
|
|
86
|
-
this.response = response;
|
|
87
|
-
this.logger = logger;
|
|
88
|
-
this.containerResolver = containerResolver;
|
|
89
|
-
/*
|
|
90
|
-
* Creating the circular reference. We do this, since request and response
|
|
91
|
-
* are meant to be extended and at times people would want to access
|
|
92
|
-
* other ctx properties like `logger`, `profiler` inside those
|
|
93
|
-
* extended methods.
|
|
94
|
-
*/
|
|
95
|
-
this.request.ctx = this;
|
|
96
|
-
this.response.ctx = this;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* A helper to see top level properties on the context object
|
|
100
|
-
*/
|
|
101
|
-
/* c8 ignore next 3 */
|
|
102
|
-
inspect() {
|
|
103
|
-
return inspect(this, false, 1, true);
|
|
104
|
-
}
|
|
105
|
-
}
|
package/build/src/qs.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { QSParserConfig } from './types/qs.js';
|
|
2
|
-
/**
|
|
3
|
-
* Query string parser used to parse and stringify query
|
|
4
|
-
* strings.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Qs {
|
|
7
|
-
#private;
|
|
8
|
-
constructor(config: QSParserConfig);
|
|
9
|
-
parse(value: string): import("qs").ParsedQs;
|
|
10
|
-
stringify(value: any): string;
|
|
11
|
-
}
|
package/build/src/qs.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { parse, stringify } from 'qs';
|
|
10
|
-
/**
|
|
11
|
-
* Query string parser used to parse and stringify query
|
|
12
|
-
* strings.
|
|
13
|
-
*/
|
|
14
|
-
export class Qs {
|
|
15
|
-
#config;
|
|
16
|
-
constructor(config) {
|
|
17
|
-
this.#config = config;
|
|
18
|
-
}
|
|
19
|
-
parse(value) {
|
|
20
|
-
return parse(value, this.#config.parse);
|
|
21
|
-
}
|
|
22
|
-
stringify(value) {
|
|
23
|
-
return stringify(value, this.#config.stringify);
|
|
24
|
-
}
|
|
25
|
-
}
|
package/build/src/redirect.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { IncomingMessage } from 'node:http';
|
|
3
|
-
import type { Qs } from './qs.js';
|
|
4
|
-
import type { Response } from './response.js';
|
|
5
|
-
import type { Router } from './router/main.js';
|
|
6
|
-
import type { MakeUrlOptions } from './types/route.js';
|
|
7
|
-
/**
|
|
8
|
-
* Exposes the API to construct redirect routes
|
|
9
|
-
*/
|
|
10
|
-
export declare class Redirect {
|
|
11
|
-
#private;
|
|
12
|
-
constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
|
|
13
|
-
/**
|
|
14
|
-
* Set a custom status code.
|
|
15
|
-
*/
|
|
16
|
-
status(statusCode: number): this;
|
|
17
|
-
/**
|
|
18
|
-
* Clearing query string values added using the
|
|
19
|
-
* "withQs" method
|
|
20
|
-
*/
|
|
21
|
-
clearQs(): this;
|
|
22
|
-
/**
|
|
23
|
-
* Define query string for the redirect. Not passing
|
|
24
|
-
* any value will forward the current request query
|
|
25
|
-
* string.
|
|
26
|
-
*/
|
|
27
|
-
withQs(): this;
|
|
28
|
-
withQs(values: Record<string, any>): this;
|
|
29
|
-
withQs(name: string, value: any): this;
|
|
30
|
-
/**
|
|
31
|
-
* Redirect to the previous path.
|
|
32
|
-
*/
|
|
33
|
-
back(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Redirect the request using a route identifier.
|
|
36
|
-
*/
|
|
37
|
-
toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
|
|
38
|
-
/**
|
|
39
|
-
* Redirect the request using a path.
|
|
40
|
-
*/
|
|
41
|
-
toPath(url: string): void;
|
|
42
|
-
}
|
package/build/src/redirect.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/http-server
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { parse } from 'node:url';
|
|
10
|
-
import encodeUrl from 'encodeurl';
|
|
11
|
-
import debug from './debug.js';
|
|
12
|
-
/**
|
|
13
|
-
* Exposes the API to construct redirect routes
|
|
14
|
-
*/
|
|
15
|
-
export class Redirect {
|
|
16
|
-
/**
|
|
17
|
-
* A boolean to forward the existing query string
|
|
18
|
-
*/
|
|
19
|
-
#forwardQueryString = false;
|
|
20
|
-
/**
|
|
21
|
-
* The status code for the redirect
|
|
22
|
-
*/
|
|
23
|
-
#statusCode = 302;
|
|
24
|
-
/**
|
|
25
|
-
* A custom query string to forward
|
|
26
|
-
*/
|
|
27
|
-
#queryString = {};
|
|
28
|
-
#request;
|
|
29
|
-
#response;
|
|
30
|
-
#router;
|
|
31
|
-
#qs;
|
|
32
|
-
constructor(request, response, router, qs) {
|
|
33
|
-
this.#request = request;
|
|
34
|
-
this.#response = response;
|
|
35
|
-
this.#router = router;
|
|
36
|
-
this.#qs = qs;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Sends response by setting require headers
|
|
40
|
-
*/
|
|
41
|
-
#sendResponse(url, query) {
|
|
42
|
-
const stringified = this.#qs.stringify(query);
|
|
43
|
-
url = stringified ? `${url}?${stringified}` : url;
|
|
44
|
-
debug('redirecting to url "%s"', url);
|
|
45
|
-
this.#response.location(encodeUrl(url));
|
|
46
|
-
this.#response.safeStatus(this.#statusCode);
|
|
47
|
-
this.#response.type('text/plain; charset=utf-8');
|
|
48
|
-
this.#response.send(`Redirecting to ${url}`);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns the referrer url
|
|
52
|
-
*/
|
|
53
|
-
#getReferrerUrl() {
|
|
54
|
-
let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
|
|
55
|
-
return Array.isArray(url) ? url[0] : url;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Set a custom status code.
|
|
59
|
-
*/
|
|
60
|
-
status(statusCode) {
|
|
61
|
-
this.#statusCode = statusCode;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Clearing query string values added using the
|
|
66
|
-
* "withQs" method
|
|
67
|
-
*/
|
|
68
|
-
clearQs() {
|
|
69
|
-
this.#forwardQueryString = false;
|
|
70
|
-
this.#queryString = {};
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
withQs(name, value) {
|
|
74
|
-
if (typeof name === 'undefined') {
|
|
75
|
-
this.#forwardQueryString = true;
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
if (typeof name === 'string') {
|
|
79
|
-
this.#queryString[name] = value;
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
Object.assign(this.#queryString, name);
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Redirect to the previous path.
|
|
87
|
-
*/
|
|
88
|
-
back() {
|
|
89
|
-
let query = {};
|
|
90
|
-
const referrerUrl = this.#getReferrerUrl();
|
|
91
|
-
const url = parse(referrerUrl);
|
|
92
|
-
debug('referrer url "%s"', referrerUrl);
|
|
93
|
-
debug('referrer base url "%s"', url.pathname);
|
|
94
|
-
/**
|
|
95
|
-
* Parse query string from the referrer url
|
|
96
|
-
*/
|
|
97
|
-
if (this.#forwardQueryString) {
|
|
98
|
-
query = this.#qs.parse(url.query || '');
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Append custom query string
|
|
102
|
-
*/
|
|
103
|
-
Object.assign(query, this.#queryString);
|
|
104
|
-
/**
|
|
105
|
-
* Redirect
|
|
106
|
-
*/
|
|
107
|
-
this.#sendResponse(url.pathname || '', query);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Redirect the request using a route identifier.
|
|
111
|
-
*/
|
|
112
|
-
toRoute(routeIdentifier, params, options) {
|
|
113
|
-
if (options && options.qs) {
|
|
114
|
-
this.withQs(options.qs);
|
|
115
|
-
options.qs = undefined;
|
|
116
|
-
}
|
|
117
|
-
const url = this.#router.makeUrl(routeIdentifier, params, options);
|
|
118
|
-
return this.toPath(url);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Redirect the request using a path.
|
|
122
|
-
*/
|
|
123
|
-
toPath(url) {
|
|
124
|
-
let query = {};
|
|
125
|
-
/**
|
|
126
|
-
* Extract query string from the current URL
|
|
127
|
-
*/
|
|
128
|
-
if (this.#forwardQueryString) {
|
|
129
|
-
query = this.#qs.parse(parse(this.#request.url).query || '');
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Assign custom query string
|
|
133
|
-
*/
|
|
134
|
-
Object.assign(query, this.#queryString);
|
|
135
|
-
/**
|
|
136
|
-
* Redirect
|
|
137
|
-
*/
|
|
138
|
-
this.#sendResponse(url, query);
|
|
139
|
-
}
|
|
140
|
-
}
|