Workbox registerRoute 问题与 Firebase 存储 CORS

问题描述 投票:0回答:0

我在尝试使用 Workbox 的

registerRoute
功能从 Firebase 存储预缓存图像时遇到了一些问题。我已经通过 Google Shell 为我正在使用的 Bucket 启用了 CORS 配置,并更改了 CacheFirst
fetchOptions
属性以包含请求的“cors”模式,但我仍然遇到很多 CORS 错误。

我的

cors.json

[
    {
        "origin": [
            "*"
        ],
        "method": [
            "GET"
        ],
        "responseHeader": [
            "Content-Type"
        ],
        "maxAgeSeconds": 3600
    }
]

我的

registerRoute
配置:

import { CacheableResponsePlugin } from 'workbox-cacheable-response';
import { CacheFirst } from 'workbox-strategies';
import { ExpirationPlugin } from 'workbox-expiration';
import { registerRoute } from 'workbox-routing';

const setup = () => {
  registerRoute(
    new RegExp('https://firebasestorage.googleapis.com/v0/b/.*'),
    new CacheFirst({
      cacheName: 'images',
      fetchOptions: {
        mode: 'cors',
      },
      plugins: [
        new CacheableResponsePlugin({
          statuses: [200],
        }),
        new ExpirationPlugin({
          maxEntries: 2000, // number of images to cache
          maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
        }),
      ],
    }),
    'GET',
  );
};

export { setup };

我做错了什么?

javascript firebase caching service-worker workbox
© www.soinside.com 2019 - 2024. All rights reserved.