next-pwa
next-pwa copied to clipboard
custom service-worker registration failed
next version : 11.0.1-canary.4 next-pwa: ^5.2.21
I've created custom worker to handle chat message sending when user offline. Followed this example
this custom worker detect stored messages in sync event from indexed db and send them in a http request to our graphql api.
It works on my localhost perfectly but it doesn't work on server. I m using azure app service for next.js project.
I have worker/index.ts file at root of project.
This is next.config.js
pwa: {
// disable: process.env.NODE_ENV === 'development',
dest: 'public',
},
This custom app file (handle service worker)
const srv = createServer((req, res) => {
if (config.useAppInsights) {
appInsights.defaultClient.trackNodeHttpRequest({
request: req,
response: res,
});
}
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
// handle GET request to /service-worker.js
if (pathname === '/sw.js' || /^\/(workbox|worker|fallback)-\w+\.js$/.test(pathname)) {
const filePath = join(__dirname, '.next', pathname);
app.serveStatic(req, res, filePath);
} else {
handleNextRequests(req, res);
}
});
I m logging some strings head of the service worker file. It is logging these strings but sync event doesn't work on server.

Any help ?
Also i have error message :

I'm wondering why it's expecting a service-worker.js file served from / root path? When you run yarn build, what files get generated inside public folder?
I'm wondering why it's expecting a
service-worker.jsfile served from/root path? When you runyarn build, what files get generated insidepublicfolder?
This is how looks after run build. My custom worker which is under worker/index.ts file, generated as worker-CXb2Co........
I'm wondering why it's expecting a
service-worker.jsfile served from/root path? When you runyarn build, what files get generated insidepublicfolder?
@shadowwalker is there any solution ? this issue blocked me. By the way error is gone probably was coming from cache. It doesn't expect /service-worker.js file. But still i can't register custom worker file.
