Skip to content

Commit

Permalink
fix(nitro): read body stream on post requests for service-worker (#527
Browse files Browse the repository at this point in the history
)
  • Loading branch information
farnabaz authored Sep 13, 2021
1 parent 134431b commit cf19a6a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/runtime/entries/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '#polyfill'
import { localCall } from '../server'

const STATIC_ASSETS_BASE = process.env.NUXT_STATIC_BASE + '/' + process.env.NUXT_STATIC_VERSION
const METHODS_WITH_BODY = ['POST', 'PUT', 'PATCH']

addEventListener('fetch', (event: any) => {
const url = new URL(event.request.url)
Expand All @@ -15,6 +16,9 @@ addEventListener('fetch', (event: any) => {
})

async function handleEvent (url, event) {
if (METHODS_WITH_BODY.includes(event.request.method.toUpperCase()) && !event.request.body) {
event.request.body = await event.request.text()
}
const r = await localCall({
event,
url: url.pathname,
Expand Down

0 comments on commit cf19a6a

Please sign in to comment.