@kiyasov/platform-hono 1.2.1 → 1.2.4
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.d.ts +2 -2
- package/dist/cjs/src/adapters/hono-adapter.js +14 -8
- 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.d.ts +2 -2
- package/dist/esm/src/adapters/hono-adapter.js +14 -8
- 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 +20 -8
package/package.json
CHANGED
|
@@ -210,19 +210,31 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
210
210
|
this.instance.use(cors(options));
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
public useBodyParser(
|
|
214
|
-
|
|
213
|
+
public useBodyParser(
|
|
214
|
+
type: TypeBodyParser,
|
|
215
|
+
rawBody?: boolean,
|
|
216
|
+
bodyLimit?: number
|
|
217
|
+
) {
|
|
218
|
+
Logger.log(
|
|
219
|
+
`Registering body parser middleware for type: ${type} | bodyLimit: ${bodyLimit}`
|
|
220
|
+
);
|
|
215
221
|
this.instance.use(this.bodyLimit(bodyLimit), async (ctx, next) => {
|
|
216
222
|
const contentType = ctx.req.header("content-type");
|
|
217
223
|
|
|
218
224
|
switch (type) {
|
|
219
225
|
case "application/json":
|
|
220
|
-
if (contentType?.startsWith("application/json"))
|
|
226
|
+
if (contentType?.startsWith("application/json")) {
|
|
227
|
+
if (rawBody) {
|
|
228
|
+
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
229
|
+
}
|
|
221
230
|
(ctx.req as any).body = await ctx.req.json();
|
|
231
|
+
}
|
|
222
232
|
break;
|
|
223
233
|
case "text/plain":
|
|
224
234
|
if (contentType?.startsWith("text/plain")) {
|
|
225
|
-
(
|
|
235
|
+
if (rawBody) {
|
|
236
|
+
(ctx.req as any).rawBody = Buffer.from(await ctx.req.text());
|
|
237
|
+
}
|
|
226
238
|
(ctx.req as any).body = await ctx.req.json();
|
|
227
239
|
}
|
|
228
240
|
break;
|
|
@@ -258,15 +270,15 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
258
270
|
return "hono";
|
|
259
271
|
}
|
|
260
272
|
|
|
261
|
-
public registerParserMiddleware(
|
|
273
|
+
public registerParserMiddleware(_prefix?: string, rawBody?: boolean) {
|
|
262
274
|
if (this._isParserRegistered) {
|
|
263
275
|
return;
|
|
264
276
|
}
|
|
265
277
|
|
|
266
278
|
Logger.log("Registering parser middleware");
|
|
267
|
-
this.useBodyParser("application/x-www-form-urlencoded");
|
|
268
|
-
this.useBodyParser("application/json");
|
|
269
|
-
this.useBodyParser("text/plain");
|
|
279
|
+
this.useBodyParser("application/x-www-form-urlencoded", rawBody);
|
|
280
|
+
this.useBodyParser("application/json", rawBody);
|
|
281
|
+
this.useBodyParser("text/plain", rawBody);
|
|
270
282
|
|
|
271
283
|
this._isParserRegistered = true;
|
|
272
284
|
}
|