fix(nitro): handle static assets and api routes for service-worker preset (#518)

This commit is contained in:
Ahad Birang 2021-09-09 20:31:43 +04:30 committed by GitHub
parent b47c592e39
commit c0c5b9b9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,10 +2,12 @@
import '#polyfill'
import { localCall } from '../server'
const STATIC_ASSETS_BASE = process.env.NUXT_STATIC_BASE + '/' + process.env.NUXT_STATIC_VERSION
addEventListener('fetch', (event: any) => {
const url = new URL(event.request.url)
if (url.pathname.includes('.') /* is file */) {
if (url.pathname.includes('.') && !url.pathname.startsWith(STATIC_ASSETS_BASE) && !url.pathname.startsWith('/api')) {
return
}