@kiyasov/platform-hono 1.3.1 → 1.3.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.
- package/dist/cjs/src/adapters/hono-adapter.js +12 -0
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.js +12 -0
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +30 -34
package/package.json
CHANGED
|
@@ -218,39 +218,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
218
218
|
Logger.log(
|
|
219
219
|
`Registering body parser middleware for type: ${type} | bodyLimit: ${bodyLimit}`
|
|
220
220
|
);
|
|
221
|
-
this.instance.use(this.bodyLimit(bodyLimit)
|
|
222
|
-
const contentType = ctx.req.header("content-type");
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
contentType?.startsWith("application/json") ||
|
|
226
|
-
contentType?.startsWith("text/plain")
|
|
227
|
-
) {
|
|
228
|
-
if (rawBody) {
|
|
229
|
-
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
230
|
-
}
|
|
231
|
-
(ctx.req as any).body = await ctx.req.json();
|
|
232
|
-
|
|
233
|
-
return await next();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (contentType !== type) {
|
|
237
|
-
return await next();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (contentType?.startsWith("application/json")) {
|
|
241
|
-
if (rawBody) {
|
|
242
|
-
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
243
|
-
}
|
|
244
|
-
(ctx.req as any).body = await ctx.req.json();
|
|
245
|
-
} else if (contentType?.startsWith("text/plain")) {
|
|
246
|
-
if (rawBody) {
|
|
247
|
-
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
248
|
-
}
|
|
249
|
-
(ctx.req as any).body = await ctx.req.json();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return await next();
|
|
253
|
-
});
|
|
221
|
+
this.instance.use(this.bodyLimit(bodyLimit));
|
|
254
222
|
|
|
255
223
|
// To avoid the Nest application init to override our custom
|
|
256
224
|
// body parser, we mark the parsers as registered.
|
|
@@ -262,10 +230,38 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
262
230
|
}
|
|
263
231
|
|
|
264
232
|
public initHttpServer(options: NestApplicationOptions) {
|
|
265
|
-
this.instance.use((ctx, next) => {
|
|
233
|
+
this.instance.use(async (ctx, next) => {
|
|
234
|
+
ctx.req["ip"] =
|
|
235
|
+
ctx.req.header("cf-connecting-ip") ??
|
|
236
|
+
ctx.req.header("x-forwarded-for") ??
|
|
237
|
+
ctx.req.header("x-real-ip") ??
|
|
238
|
+
ctx.req.header("forwarded") ??
|
|
239
|
+
ctx.req.header("true-client-ip") ??
|
|
240
|
+
ctx.req.header("x-client-ip") ??
|
|
241
|
+
ctx.req.header("x-cluster-client-ip") ??
|
|
242
|
+
ctx.req.header("x-forwarded") ??
|
|
243
|
+
ctx.req.header("forwarded-for") ??
|
|
244
|
+
ctx.req.header("via");
|
|
266
245
|
ctx.req["query"] = ctx.req.query() as any;
|
|
267
246
|
ctx.req["headers"] = Object.fromEntries(ctx.req.raw.headers);
|
|
268
247
|
|
|
248
|
+
const contentType = ctx.req.header("content-type");
|
|
249
|
+
|
|
250
|
+
if (
|
|
251
|
+
contentType?.startsWith("multipart/form-data") ||
|
|
252
|
+
contentType?.startsWith("application/x-www-form-urlencoded")
|
|
253
|
+
) {
|
|
254
|
+
(ctx.req as any).body = await ctx.req.parseBody();
|
|
255
|
+
} else if (
|
|
256
|
+
contentType?.startsWith("application/json") ||
|
|
257
|
+
contentType?.startsWith("text/plain")
|
|
258
|
+
) {
|
|
259
|
+
if (options.rawBody) {
|
|
260
|
+
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
261
|
+
}
|
|
262
|
+
(ctx.req as any).body = await ctx.req.json();
|
|
263
|
+
}
|
|
264
|
+
|
|
269
265
|
return next();
|
|
270
266
|
});
|
|
271
267
|
const isHttpsEnabled = options?.httpsOptions;
|