Skip to content

Commit

Permalink
fix(deno, lagon, sw): fix request body handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 16, 2023
1 parent c75c2f1 commit 1c88e5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/runtime/entries/deno.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import "#internal/nitro/virtual/polyfill";
// @ts-ignore
import { serve } from "https://deno.land/std/http/server.ts";

import { requestHasBody, useRequestBody } from "../utils";
import { nitroApp } from "../app";

serve((request: Request) => {
Expand All @@ -11,9 +9,11 @@ serve((request: Request) => {

async function handleRequest(request: Request) {
const url = new URL(request.url);

// https://deno.land/api?s=Body
let body;
if (requestHasBody(request)) {
body = await useRequestBody(request);
if (request.body) {
body = await request.arrayBuffer();
}

const r = await nitroApp.localCall({
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/entries/lagon.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "#internal/nitro/virtual/polyfill";
import { requestHasBody, useRequestBody } from "#internal/nitro/utils";
import { nitroApp } from "#internal/nitro/app";

export async function handler(request: Request): Promise<Response> {
const url = new URL(request.url);

let body;
if (requestHasBody(request)) {
body = await useRequestBody(request);
if (request.body) {
body = await request.arrayBuffer();
}

const r = await nitroApp.localCall({
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/entries/service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "#internal/nitro/virtual/polyfill";
import { requestHasBody, useRequestBody } from "../utils";
import { nitroApp } from "../app";
import { isPublicAssetURL } from "#internal/nitro/virtual/public-assets";

Expand All @@ -14,8 +13,8 @@ addEventListener("fetch", (event: any) => {

async function handleEvent(url, event) {
let body;
if (requestHasBody(event.request)) {
body = await useRequestBody(event.request);
if (event.request.body) {
body = await event.request.arrayBuffer();
}

const r = await nitroApp.localCall({
Expand Down

0 comments on commit 1c88e5e

Please sign in to comment.