fix(nitro): read body stream on post requests for service-worker (#527)

This commit is contained in:
Ahad Birang 2021-09-13 15:07:38 +04:30 committed by GitHub
parent 2c82c27960
commit 13abec6143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import '#polyfill'
import { localCall } from '../server' import { localCall } from '../server'
const STATIC_ASSETS_BASE = process.env.NUXT_STATIC_BASE + '/' + process.env.NUXT_STATIC_VERSION 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) => { addEventListener('fetch', (event: any) => {
const url = new URL(event.request.url) const url = new URL(event.request.url)
@ -15,6 +16,9 @@ addEventListener('fetch', (event: any) => {
}) })
async function handleEvent (url, event) { 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({ const r = await localCall({
event, event,
url: url.pathname, url: url.pathname,