move config of service worker to msw files

This commit is contained in:
Mads Rasmussen
2022-06-03 13:09:03 +02:00
parent 6821e151e8
commit 1f0218e05b
2 changed files with 14 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
import 'element-internals-polyfill';
import { worker } from './mocks/browser';
import { startMockServiceWorker } from './mocks/browser';
import { UmbExtensionRegistry, UmbExtensionManifest, UmbExtensionManifestCore } from './core/extension';
const extensionRegistry = new UmbExtensionRegistry();
@@ -153,14 +153,5 @@ const setup = async () => {
await import('./app');
};
worker.start({
onUnhandledRequest: (req) => {
if (req.url.pathname.startsWith('/node_modules/')) return;
if (req.url.pathname.startsWith('/src/')) return;
if (req.destination === 'image') return;
console.warn('Found an unhandled %s request to %s', req.method, req.url.href);
},
});
setup();
startMockServiceWorker();
setup();

View File

@@ -1,4 +1,14 @@
import { setupWorker } from 'msw';
import { handlers } from './handlers';
export const worker = setupWorker(...handlers);
const worker = setupWorker(...handlers);
export const startMockServiceWorker = () => worker.start({
onUnhandledRequest: (req) => {
if (req.url.pathname.startsWith('/node_modules/')) return;
if (req.url.pathname.startsWith('/src/')) return;
if (req.destination === 'image') return;
console.warn('Found an unhandled %s request to %s', req.method, req.url.href);
},
});