@nestjs/platform-fastify 12.0.1 → 12.0.3
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.
|
@@ -125,8 +125,24 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
|
|
|
125
125
|
private registerMiddie;
|
|
126
126
|
private getRequestOriginalUrl;
|
|
127
127
|
private injectRouteOptions;
|
|
128
|
+
/**
|
|
129
|
+
* Fastify still accepts the router options ("ignoreTrailingSlash",
|
|
130
|
+
* "caseSensitive", ...) at the top level, but "initialConfig.routerOptions"
|
|
131
|
+
* only reflects them when they are passed through "routerOptions". As the
|
|
132
|
+
* adapter always passes "routerOptions" (for the version constraint), the
|
|
133
|
+
* top-level values are folded in so that plugins relying on
|
|
134
|
+
* "initialConfig.routerOptions" (like @fastify/middie) normalize request
|
|
135
|
+
* paths exactly like the router does.
|
|
136
|
+
*/
|
|
137
|
+
private getTopLevelRouterOptions;
|
|
128
138
|
private sanitizeUrl;
|
|
129
139
|
private removeDuplicateSlashes;
|
|
130
140
|
private trimLastSlash;
|
|
141
|
+
/**
|
|
142
|
+
* Mirrors the absolute-form request target handling of "find-my-way".
|
|
143
|
+
* Returns the path of an absolute-form target ("http://host/path" -> "/path")
|
|
144
|
+
* and leaves any other request target untouched.
|
|
145
|
+
*/
|
|
146
|
+
private getPathFromRequestTarget;
|
|
131
147
|
}
|
|
132
148
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { HttpException, HttpStatus, Logger, StreamableFile, VERSION_NEUTRAL, VersioningType, } from '@nestjs/common';
|
|
2
2
|
import { fastify, } from 'fastify';
|
|
3
|
-
import
|
|
3
|
+
import Reply from 'fastify/lib/reply.js';
|
|
4
4
|
import fastifySymbols from 'fastify/lib/symbols.js';
|
|
5
5
|
import { pathToRegexp } from 'path-to-regexp';
|
|
6
|
+
import middie from '@fastify/middie';
|
|
6
7
|
import { loadPackage, isNil, isString, isUndefined, } from '@nestjs/common/internal';
|
|
7
8
|
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
8
9
|
import { LegacyRouteConverter } from '@nestjs/core/internal';
|
|
@@ -11,7 +12,6 @@ const { kRouteContext } = fastifySymbols;
|
|
|
11
12
|
import { parse as querystringParse } from 'fast-querystring';
|
|
12
13
|
import urlSanitizer from 'find-my-way/lib/url-sanitizer.js';
|
|
13
14
|
import { FASTIFY_ROUTE_CONFIG_METADATA, FASTIFY_ROUTE_CONSTRAINTS_METADATA, FASTIFY_ROUTE_SCHEMA_METADATA, } from '../constants.js';
|
|
14
|
-
import middie from './middie/fastify-middie.js';
|
|
15
15
|
const { safeDecodeURI } = urlSanitizer;
|
|
16
16
|
/**
|
|
17
17
|
* @publicApi
|
|
@@ -68,7 +68,7 @@ export class FastifyAdapter extends AbstractHttpAdapter {
|
|
|
68
68
|
const acceptHeaderValue = (req.headers?.[MEDIA_TYPE_HEADER] || req.headers?.[MEDIA_TYPE_HEADER.toLowerCase()]);
|
|
69
69
|
const acceptHeaderVersionParameter = acceptHeaderValue
|
|
70
70
|
? acceptHeaderValue.split(';')[1]
|
|
71
|
-
:
|
|
71
|
+
: undefined;
|
|
72
72
|
return isUndefined(acceptHeaderVersionParameter)
|
|
73
73
|
? VERSION_NEUTRAL // No version was supplied
|
|
74
74
|
: acceptHeaderVersionParameter.split(this.versioningOptions.key)[1];
|
|
@@ -99,6 +99,7 @@ export class FastifyAdapter extends AbstractHttpAdapter {
|
|
|
99
99
|
: fastify({
|
|
100
100
|
...instanceOrOptions,
|
|
101
101
|
routerOptions: {
|
|
102
|
+
...this.getTopLevelRouterOptions(instanceOrOptions),
|
|
102
103
|
...instanceOrOptions?.routerOptions,
|
|
103
104
|
constraints: {
|
|
104
105
|
version: this.versionConstraint,
|
|
@@ -540,9 +541,39 @@ export class FastifyAdapter extends AbstractHttpAdapter {
|
|
|
540
541
|
}
|
|
541
542
|
return this.instance.route(routeToInject);
|
|
542
543
|
}
|
|
544
|
+
/**
|
|
545
|
+
* Fastify still accepts the router options ("ignoreTrailingSlash",
|
|
546
|
+
* "caseSensitive", ...) at the top level, but "initialConfig.routerOptions"
|
|
547
|
+
* only reflects them when they are passed through "routerOptions". As the
|
|
548
|
+
* adapter always passes "routerOptions" (for the version constraint), the
|
|
549
|
+
* top-level values are folded in so that plugins relying on
|
|
550
|
+
* "initialConfig.routerOptions" (like @fastify/middie) normalize request
|
|
551
|
+
* paths exactly like the router does.
|
|
552
|
+
*/
|
|
553
|
+
getTopLevelRouterOptions(options) {
|
|
554
|
+
const routerOptions = {};
|
|
555
|
+
const routerOptionKeys = [
|
|
556
|
+
'ignoreTrailingSlash',
|
|
557
|
+
'ignoreDuplicateSlashes',
|
|
558
|
+
'caseSensitive',
|
|
559
|
+
'useSemicolonDelimiter',
|
|
560
|
+
'maxParamLength',
|
|
561
|
+
'allowUnsafeRegex',
|
|
562
|
+
];
|
|
563
|
+
for (const key of routerOptionKeys) {
|
|
564
|
+
if (options?.[key] !== undefined) {
|
|
565
|
+
routerOptions[key] = options[key];
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return routerOptions;
|
|
569
|
+
}
|
|
543
570
|
sanitizeUrl(url) {
|
|
544
571
|
const initialConfig = this.instance.initialConfig;
|
|
545
572
|
const routerOptions = initialConfig.routerOptions;
|
|
573
|
+
// Absolute-form request targets ("GET http://host/path HTTP/1.1") must be
|
|
574
|
+
// resolved to their path before any other normalization, as the Fastify
|
|
575
|
+
// router does, so that middleware and routes always match the same path.
|
|
576
|
+
url = this.getPathFromRequestTarget(url);
|
|
546
577
|
if (routerOptions.ignoreDuplicateSlashes ||
|
|
547
578
|
initialConfig.ignoreDuplicateSlashes) {
|
|
548
579
|
url = this.removeDuplicateSlashes(url);
|
|
@@ -570,4 +601,29 @@ export class FastifyAdapter extends AbstractHttpAdapter {
|
|
|
570
601
|
}
|
|
571
602
|
return path;
|
|
572
603
|
}
|
|
604
|
+
/**
|
|
605
|
+
* Mirrors the absolute-form request target handling of "find-my-way".
|
|
606
|
+
* Returns the path of an absolute-form target ("http://host/path" -> "/path")
|
|
607
|
+
* and leaves any other request target untouched.
|
|
608
|
+
*/
|
|
609
|
+
getPathFromRequestTarget(url) {
|
|
610
|
+
if (url.charCodeAt(0) === 47 /* '/' */) {
|
|
611
|
+
return url;
|
|
612
|
+
}
|
|
613
|
+
const schemeEnd = url.indexOf('://');
|
|
614
|
+
if (schemeEnd === -1) {
|
|
615
|
+
return url;
|
|
616
|
+
}
|
|
617
|
+
const scheme = url.slice(0, schemeEnd).toLowerCase();
|
|
618
|
+
if (scheme !== 'http' && scheme !== 'https') {
|
|
619
|
+
return url;
|
|
620
|
+
}
|
|
621
|
+
const authorityStart = schemeEnd + 3;
|
|
622
|
+
const pathStart = url.indexOf('/', authorityStart);
|
|
623
|
+
if (pathStart === authorityStart || !URL.canParse(url)) {
|
|
624
|
+
// Malformed target: the router rejects it before any middleware runs
|
|
625
|
+
return url;
|
|
626
|
+
}
|
|
627
|
+
return pathStart === -1 ? '/' : url.slice(pathStart);
|
|
628
|
+
}
|
|
573
629
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-fastify",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.3",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,13 +27,12 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@fastify/cors": "11.3.0",
|
|
29
29
|
"@fastify/formbody": "9.0.0",
|
|
30
|
+
"@fastify/middie": "9.3.4",
|
|
30
31
|
"fast-querystring": "1.1.2",
|
|
31
|
-
"fastify": "5.12.
|
|
32
|
-
"fastify-plugin": "6.0.0",
|
|
32
|
+
"fastify": "5.12.4",
|
|
33
33
|
"find-my-way": "9.9.0",
|
|
34
34
|
"light-my-request": "6.6.0",
|
|
35
35
|
"path-to-regexp": "8.4.2",
|
|
36
|
-
"reusify": "1.1.0",
|
|
37
36
|
"tslib": "2.8.1"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
@@ -50,5 +49,5 @@
|
|
|
50
49
|
"optional": true
|
|
51
50
|
}
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "14151790e1abe870abc3bbf00f88786fc3ebe509"
|
|
54
53
|
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { FastifyInstance, FastifyPluginCallback } from 'fastify';
|
|
2
|
-
import * as http from 'node:http';
|
|
3
|
-
export type MiddlewareFn<Req extends {
|
|
4
|
-
url: string;
|
|
5
|
-
originalUrl?: string;
|
|
6
|
-
}, Res extends {
|
|
7
|
-
finished?: boolean;
|
|
8
|
-
writableEnded?: boolean;
|
|
9
|
-
}, Ctx = unknown> = (req: Req, res: Res, next: (err?: unknown) => void) => void;
|
|
10
|
-
declare const supportedHooks: readonly ["onError", "onSend", "preParsing", "preSerialization", "onRequest", "onResponse", "onTimeout", "preHandler", "preValidation"];
|
|
11
|
-
type SupportedHook = (typeof supportedHooks)[number];
|
|
12
|
-
interface MiddieOptions {
|
|
13
|
-
hook?: SupportedHook;
|
|
14
|
-
}
|
|
15
|
-
declare function fastifyMiddie(fastify: FastifyInstance, options: MiddieOptions, next: (err?: Error) => void): void;
|
|
16
|
-
declare namespace fastifyMiddie {
|
|
17
|
-
export interface FastifyMiddieOptions {
|
|
18
|
-
hook?: 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization' | 'onSend' | 'onResponse' | 'onTimeout' | 'onError';
|
|
19
|
-
}
|
|
20
|
-
type FastifyMiddie = FastifyPluginCallback<fastifyMiddie.FastifyMiddieOptions>;
|
|
21
|
-
export interface IncomingMessageExtended {
|
|
22
|
-
body?: any;
|
|
23
|
-
query?: any;
|
|
24
|
-
}
|
|
25
|
-
export type NextFunction = (err?: any) => void;
|
|
26
|
-
export type SimpleHandleFunction = (req: http.IncomingMessage & IncomingMessageExtended, res: http.ServerResponse) => void;
|
|
27
|
-
export type NextHandleFunction = (req: http.IncomingMessage & IncomingMessageExtended, res: http.ServerResponse, next: NextFunction) => void;
|
|
28
|
-
export type Handler = SimpleHandleFunction | NextHandleFunction;
|
|
29
|
-
export const fastifyMiddie: FastifyMiddie;
|
|
30
|
-
export { fastifyMiddie as default };
|
|
31
|
-
}
|
|
32
|
-
declare module 'fastify' {
|
|
33
|
-
interface FastifyInstance {
|
|
34
|
-
use(fn: fastifyMiddie.Handler): this;
|
|
35
|
-
use(route: string, fn: fastifyMiddie.Handler): this;
|
|
36
|
-
use(routes: string[], fn: fastifyMiddie.Handler): this;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* A clone of `@fastify/middie` engine https://github.com/fastify/middie
|
|
41
|
-
* with an extra vulnerability fix. Path is now decoded before matching to
|
|
42
|
-
* avoid bypassing middleware with encoded characters.
|
|
43
|
-
*/
|
|
44
|
-
declare const _default: typeof fastifyMiddie;
|
|
45
|
-
export default _default;
|
|
46
|
-
export { fastifyMiddie };
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import fp from 'fastify-plugin';
|
|
2
|
-
import urlSanitizer from 'find-my-way/lib/url-sanitizer.js';
|
|
3
|
-
import { pathToRegexp } from 'path-to-regexp';
|
|
4
|
-
import reusify from 'reusify';
|
|
5
|
-
const { safeDecodeURI } = urlSanitizer;
|
|
6
|
-
function bindLast(fn, last) {
|
|
7
|
-
return (...args) => fn(...args, last);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* A clone of `@fastify/middie` engine https://github.com/fastify/middie
|
|
11
|
-
* with an extra vulnerability fix. Path is now decoded before matching to
|
|
12
|
-
* avoid bypassing middleware with encoded characters.
|
|
13
|
-
*/
|
|
14
|
-
function middie(complete, initialConfig) {
|
|
15
|
-
const middlewares = [];
|
|
16
|
-
const pool = reusify(Holder);
|
|
17
|
-
return {
|
|
18
|
-
use,
|
|
19
|
-
run: bindLast(run, initialConfig),
|
|
20
|
-
};
|
|
21
|
-
function use(url, f) {
|
|
22
|
-
if (f === undefined) {
|
|
23
|
-
f = url;
|
|
24
|
-
url = null;
|
|
25
|
-
}
|
|
26
|
-
let regexp;
|
|
27
|
-
if (typeof url === 'string') {
|
|
28
|
-
const pathRegExp = pathToRegexp(sanitizePrefixUrl(url), {
|
|
29
|
-
end: false,
|
|
30
|
-
});
|
|
31
|
-
regexp = pathRegExp.regexp;
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(f)) {
|
|
34
|
-
for (const val of f) {
|
|
35
|
-
middlewares.push({ regexp, fn: val });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
middlewares.push({ regexp, fn: f });
|
|
40
|
-
}
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
function run(req, res, ctx, initialConfig) {
|
|
44
|
-
if (!middlewares.length) {
|
|
45
|
-
complete(null, req, res, ctx);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
req.originalUrl = req.url;
|
|
49
|
-
const holder = pool.get();
|
|
50
|
-
holder.req = req;
|
|
51
|
-
holder.res = res;
|
|
52
|
-
holder.url = sanitizeUrl(req.url);
|
|
53
|
-
holder.context = ctx;
|
|
54
|
-
holder.initialConfig = initialConfig;
|
|
55
|
-
holder.done();
|
|
56
|
-
}
|
|
57
|
-
function Holder() {
|
|
58
|
-
this.req = null;
|
|
59
|
-
this.res = null;
|
|
60
|
-
this.url = null;
|
|
61
|
-
this.context = null;
|
|
62
|
-
this.initialConfig = null;
|
|
63
|
-
this.i = 0;
|
|
64
|
-
const that = this;
|
|
65
|
-
this.done = function (err) {
|
|
66
|
-
const req = that.req;
|
|
67
|
-
const res = that.res;
|
|
68
|
-
const url = that.url;
|
|
69
|
-
const context = that.context;
|
|
70
|
-
const i = that.i++;
|
|
71
|
-
req.url = req.originalUrl;
|
|
72
|
-
if (res.finished === true || res.writableEnded === true) {
|
|
73
|
-
cleanup();
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (err || middlewares.length === i) {
|
|
77
|
-
complete(err, req, res, context);
|
|
78
|
-
cleanup();
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const { fn, regexp } = middlewares[i];
|
|
82
|
-
if (regexp) {
|
|
83
|
-
// Decode URL before matching to avoid bypassing middleware
|
|
84
|
-
let sanitizedUrl = url;
|
|
85
|
-
if (that.initialConfig.ignoreDuplicateSlashes ||
|
|
86
|
-
that.initialConfig.routerOptions?.ignoreDuplicateSlashes) {
|
|
87
|
-
sanitizedUrl = removeDuplicateSlashes(sanitizedUrl);
|
|
88
|
-
}
|
|
89
|
-
if (that.initialConfig.ignoreTrailingSlash ||
|
|
90
|
-
that.initialConfig.routerOptions?.ignoreTrailingSlash) {
|
|
91
|
-
sanitizedUrl = trimLastSlash(sanitizedUrl);
|
|
92
|
-
}
|
|
93
|
-
if (that.initialConfig.caseSensitive === false ||
|
|
94
|
-
that.initialConfig.routerOptions?.caseSensitive === false) {
|
|
95
|
-
sanitizedUrl = sanitizedUrl.toLowerCase();
|
|
96
|
-
}
|
|
97
|
-
const decodedUrl = safeDecodeURI(sanitizedUrl, that.initialConfig?.routerOptions?.useSemicolonDelimiter ||
|
|
98
|
-
that.initialConfig?.useSemicolonDelimiter).path;
|
|
99
|
-
const result = regexp.exec(decodedUrl);
|
|
100
|
-
if (result) {
|
|
101
|
-
req.url = req.url.replace(result[0], '');
|
|
102
|
-
if (req.url[0] !== '/')
|
|
103
|
-
req.url = '/' + req.url;
|
|
104
|
-
fn(req, res, that.done);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
that.done();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
fn(req, res, that.done);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
function cleanup() {
|
|
116
|
-
that.req = null;
|
|
117
|
-
that.res = null;
|
|
118
|
-
that.context = null;
|
|
119
|
-
that.initialConfig = null;
|
|
120
|
-
that.i = 0;
|
|
121
|
-
pool.release(that);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function removeDuplicateSlashes(path) {
|
|
126
|
-
const REMOVE_DUPLICATE_SLASHES_REGEXP = /\/\/+/g;
|
|
127
|
-
return path.indexOf('//') !== -1
|
|
128
|
-
? path.replace(REMOVE_DUPLICATE_SLASHES_REGEXP, '/')
|
|
129
|
-
: path;
|
|
130
|
-
}
|
|
131
|
-
function trimLastSlash(path) {
|
|
132
|
-
if (path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
133
|
-
return path.slice(0, -1);
|
|
134
|
-
}
|
|
135
|
-
return path;
|
|
136
|
-
}
|
|
137
|
-
function sanitizeUrl(url) {
|
|
138
|
-
for (let i = 0, len = url.length; i < len; i++) {
|
|
139
|
-
const charCode = url.charCodeAt(i);
|
|
140
|
-
if (charCode === 63 || charCode === 35) {
|
|
141
|
-
return url.slice(0, i);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return url;
|
|
145
|
-
}
|
|
146
|
-
function sanitizePrefixUrl(url) {
|
|
147
|
-
if (url === '/')
|
|
148
|
-
return '';
|
|
149
|
-
if (url[url.length - 1] === '/')
|
|
150
|
-
return url.slice(0, -1);
|
|
151
|
-
return url;
|
|
152
|
-
}
|
|
153
|
-
const kMiddlewares = Symbol('fastify-middie-middlewares');
|
|
154
|
-
const kMiddie = Symbol('fastify-middie-instance');
|
|
155
|
-
const kMiddieHasMiddlewares = Symbol('fastify-middie-has-middlewares');
|
|
156
|
-
const supportedHooksWithPayload = [
|
|
157
|
-
'onError',
|
|
158
|
-
'onSend',
|
|
159
|
-
'preParsing',
|
|
160
|
-
'preSerialization',
|
|
161
|
-
];
|
|
162
|
-
const supportedHooksWithoutPayload = [
|
|
163
|
-
'onRequest',
|
|
164
|
-
'onResponse',
|
|
165
|
-
'onTimeout',
|
|
166
|
-
'preHandler',
|
|
167
|
-
'preValidation',
|
|
168
|
-
];
|
|
169
|
-
const supportedHooks = [
|
|
170
|
-
...supportedHooksWithPayload,
|
|
171
|
-
...supportedHooksWithoutPayload,
|
|
172
|
-
];
|
|
173
|
-
function fastifyMiddie(fastify, options, next) {
|
|
174
|
-
fastify.decorate('use', use);
|
|
175
|
-
fastify[kMiddlewares] = [];
|
|
176
|
-
fastify[kMiddieHasMiddlewares] = false;
|
|
177
|
-
fastify[kMiddie] = middie(onMiddieEnd, fastify.initialConfig);
|
|
178
|
-
const hook = options.hook || 'onRequest';
|
|
179
|
-
if (!supportedHooks.includes(hook)) {
|
|
180
|
-
next(new Error(`The hook "${hook}" is not supported by fastify-middie`));
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
fastify
|
|
184
|
-
.addHook(hook, supportedHooksWithPayload.includes(hook)
|
|
185
|
-
? runMiddieWithPayload
|
|
186
|
-
: runMiddie)
|
|
187
|
-
.addHook('onRegister', onRegister);
|
|
188
|
-
function use(path, fn) {
|
|
189
|
-
if (typeof path === 'string') {
|
|
190
|
-
const prefix = this.prefix;
|
|
191
|
-
path = prefix + (path === '/' && prefix.length > 0 ? '' : path);
|
|
192
|
-
}
|
|
193
|
-
this[kMiddlewares].push([path, fn]);
|
|
194
|
-
if (fn == null) {
|
|
195
|
-
this[kMiddie].use(path);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
this[kMiddie].use(path, fn);
|
|
199
|
-
}
|
|
200
|
-
this[kMiddieHasMiddlewares] = true;
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
function runMiddie(req, reply, next) {
|
|
204
|
-
if (this[kMiddieHasMiddlewares]) {
|
|
205
|
-
const raw = req.raw;
|
|
206
|
-
raw.id = req.id;
|
|
207
|
-
raw.hostname = req.hostname;
|
|
208
|
-
raw.protocol = req.protocol;
|
|
209
|
-
raw.ip = req.ip;
|
|
210
|
-
raw.ips = req.ips;
|
|
211
|
-
raw.log = req.log;
|
|
212
|
-
req.raw.query = req.query;
|
|
213
|
-
reply.raw.log = req.log;
|
|
214
|
-
if (req.body !== undefined)
|
|
215
|
-
req.raw.body = req.body;
|
|
216
|
-
this[kMiddie].run(req.raw, reply.raw, next);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
next();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function runMiddieWithPayload(req, reply, _payload, next) {
|
|
223
|
-
runMiddie.bind(this)(req, reply, next);
|
|
224
|
-
}
|
|
225
|
-
function onMiddieEnd(err, _req, _res, next) {
|
|
226
|
-
next(err);
|
|
227
|
-
}
|
|
228
|
-
function onRegister(instance) {
|
|
229
|
-
const middlewares = instance[kMiddlewares].slice();
|
|
230
|
-
instance[kMiddlewares] = [];
|
|
231
|
-
instance[kMiddie] = middie(onMiddieEnd, instance.initialConfig);
|
|
232
|
-
instance[kMiddieHasMiddlewares] = false;
|
|
233
|
-
instance.decorate('use', use);
|
|
234
|
-
for (const middleware of middlewares) {
|
|
235
|
-
instance[kMiddlewares].push(middleware);
|
|
236
|
-
instance[kMiddie].use(...middleware);
|
|
237
|
-
}
|
|
238
|
-
instance[kMiddieHasMiddlewares] = middlewares.length > 0;
|
|
239
|
-
}
|
|
240
|
-
next();
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* A clone of `@fastify/middie` engine https://github.com/fastify/middie
|
|
244
|
-
* with an extra vulnerability fix. Path is now decoded before matching to
|
|
245
|
-
* avoid bypassing middleware with encoded characters.
|
|
246
|
-
*/
|
|
247
|
-
export default fp(fastifyMiddie, {
|
|
248
|
-
fastify: '5.x',
|
|
249
|
-
name: '@fastify/middie',
|
|
250
|
-
});
|
|
251
|
-
export { fastifyMiddie };
|