Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad HTTP response (Maybe 404?) #229

Open
thedevdavid opened this issue Mar 15, 2020 · 2 comments
Open

Bad HTTP response (Maybe 404?) #229

thedevdavid opened this issue Mar 15, 2020 · 2 comments

Comments

@thedevdavid
Copy link

thedevdavid commented Mar 15, 2020

Hey!
I've configured next-offline with next-componse plugins & now 2 with the following setup:

next config:

const workboxOpts = {
  swDest: 'static/service-worker.js',
  runtimeCaching: [
....
    {
      urlPattern: /^https?.*/,
      handler: 'NetworkFirst',
      options: {
        cacheName: 'https-calls',
        networkTimeoutSeconds: 15,
        expiration: {
          maxEntries: 150,
          maxAgeSeconds: 30 * 24 * 60 * 60, // 1 month
        },
        cacheableResponse: {
          statuses: [0, 200],
        },
      },
    },
  ],
};

const config = {
  env,
  reactStrictMode: true,
  workboxOpts,
  generateInDevMode: true,
  transformManifest: manifest => ['/'].concat(manifest),
};
now.json
{
  "version": 2,
  "public": false,
  "builds": [
    {
      "src": "next.config.js",
      "use": "@now/next@canary"
    }
  ],
  "build": {
    "env": {
     ...
    }
  },
  "rewrites": [
    { "source": "/", "destination": "/" },
    {
      "source": "^/service-worker.js$",
      "destination": "/_next/static/service-worker.js"
    }
  ],
  "headers": [
    {
			"source": "^/service-worker.js$",
			"headers": [
				{
					"key": "cache-control",
					"value": "public, max-age=43200, immutable"
				},
				{
					"key": "Service-Worker-Allowed",
					"value": "/(.+)"
				}
			]
    },
    {
      "source": "/(.+)",
      "headers" : [
        {
          "key" : "X-Content-Type-Options",
          "value" : "nosniff"
        },
        {
          "key" : "X-Frame-Options",
          "value" : "DENY"
        },
        {
          "key" : "X-XSS-Protection",
          "value" : "1; mode=block"
        }
      ]
    }
  ]
}

Devtools shows it's generates multiple but I can't see it from Source
image

The error:
SW registration failed: TypeError: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/service-worker.js'): A bad HTTP response code (404) was received when fetching the script.

It runs on the latest Next (9.3) and latest next-offline (5.0)

Link: https://web.qa.unipieapp.com

@thedevdavid thedevdavid changed the title Unsupported MIME type (Maybe 404?) Bad HTTP response (Maybe 404?) Mar 22, 2020
@Quadriphobs1
Copy link

Same here I can see the service-worker.js file created however its not been served when using express setup and results in 404 error

@AlexWheeler
Copy link

@DLevai94, @Quadriphobs1

I had same issue, but got this working with the following config:
Note how I'm telling workbox to put the generated service-worker.js into ../public/

This way when the app is built next serves it at /service-worker.js

const withOffline = require('next-offline')
const config = {
  workboxOpts: {
    swDest: '../public/service-worker.js',
  },
	// rest of your config
}
module.exports = withOffline(config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants