title: Service Worker registration fails with firebase hosting and functions
body: <p>Service Worker is not registered with an application builded by Nuxt.js (Universal) which is running on Firebase Functions.</p>
  
  <p>I'm currently trying to build a prototype web application with Nuxt.js Universal mode and Firebase Functions.
  The app uses service worker with nuxt official pwa-module to manage the session of logged in user, so that the client could send the request with authorization header to the server and server would verify the user session via Firebase Authentication.</p>
  
  <p>I've already tried to run it on local server with <code>yarn run build</code> and <code>yarn run start</code>, and ensured the service worker have been correctly registered and worked perfectly.
  However when I try to check the same operation with <code>firebase serve</code>, I receive following errors on the browser.</p>
  
  <pre><code>A bad HTTP response code (404) was received when fetching the script.
  Failed to load resource: net::ERR_INVALID_RESPONSE
  dcbac67bb39a765db27a.js:1 Service worker registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
  </code></pre>
  
  <p>I also found that the service worker does not send the session data to the server. Exactly same thing was reproduced when I deployed source into production with <code>firebase deploy</code>.</p>
  
  <p>It even occurs when I completely clean project with <code>yarn create nuxt-app</code>, <code>yarn run build</code> and <code>firebase serve</code>. "sw.js" file indicates failed status on Chrome developer tool.</p>
  
  <p>I'm not sure if it is concerned but my Firebase is on Spark plan.</p>
  
  <p>My project tree.</p>
  
  <pre><code>.
  ├── firebase.json
  ├── firestore.indexes.json
  ├── firestore.rules
  ├── functions
  │   ├── index.js
  │   ├── nuxt
  │   │   ├── App.js
  │   │   ├── axios.js
  │   │   ├── client.js
  │   │   ├── components
  │   │   ├── dist
  │   │   ├── empty.js
  │   │   ├── index.js
  │   │   ├── loading.html
  │   │   ├── middleware.js
  │   │   ├── router.js
  │   │   ├── server.js
  │   │   ├── store.js
  │   │   ├── sw.plugin.js
  │   │   ├── sw.template.js
  │   │   ├── utils.js
  │   │   └── views
  │   ├── package-lock.json
  │   ├── package.json
  │   └── yarn.lock
  ├── public
  └── src
      ├── assets
      ├── components
      ├── jest.config.js
      ├── layouts
      ├── middleware
      ├── nuxt.config.js
      ├── package.json
      ├── pages
      ├── plugins
      ├── server
      ├── static
      │   └── sw.js
      ├── store
      └── test
      └── yarn.lock
  </code></pre>
  
  <p>src/static/sw.js</p>
  
  <pre><code>importScripts('/_nuxt/workbox.4c4f5ca6.js')
  
  workbox.precaching.precacheAndRoute([
    {
      "url": "/_nuxt/021e1640b53136b75c48.js",
      "revision": "2753e747206d803c793b59a324c1931b"
    },
    {
      "url": "/_nuxt/03c9e340d8692d1403a9.js",
      "revision": "2b882d73d20a0b2cfd318e9e05d3496e"
    },
    {
      "url": "/_nuxt/78bddfa6b6a4919b78d6.js",
      "revision": "70312f6623089e3b4aa6454120c1e177"
    },
    {
      "url": "/_nuxt/85c817abccdd40162004.js",
      "revision": "45448f8709d01af59bb125a1d06be23a"
    },
    {
      "url": "/_nuxt/8654a518d0f3e326c9a6.js",
      "revision": "a42426f5e7b458acc6fdf0e9e48c7d35"
    },
    {
      "url": "/_nuxt/95b421159066eff9e318.js",
      "revision": "efd1643042f804defa7212979867558a"
    },
    {
      "url": "/_nuxt/9b487bf2df1190b68565.js",
      "revision": "78837d0e624deccc85761b44f9ede9be"
    },
    {
      "url": "/_nuxt/ce59381752309c170d41.js",
      "revision": "d3e50bf27891c4efa6dff5076a0772a6"
    },
    {
      "url": "/_nuxt/d8fa6ae5ca14331879f6.js",
      "revision": "5da6698c9359df803243ecc44519b610"
    },
    {
      "url": "/_nuxt/dcbac67bb39a765db27a.js",
      "revision": "9505aa84ddb2a70b826d324433daff36"
    },
    {
      "url": "/_nuxt/dee89eef613849499c7f.js",
      "revision": "43117ed819efe3d00c963dd655894d5f"
    }
  ], {
    "cacheId": "justtest",
    "directoryIndex": "/",
    "cleanUrls": false
  })
  
  workbox.clientsClaim()
  workbox.skipWaiting()
  
  workbox.routing.registerRoute(new RegExp('/_nuxt/.*'), workbox.strategies.cacheFirst({}), 'GET')
  
  workbox.routing.registerRoute(new RegExp('/.*'), workbox.strategies.networkFirst({}), 'GET')
  </code></pre>
  
  <p>functions/index.js</p>
  
  <pre><code>const functions = require("firebase-functions")
  const { Nuxt } = require("nuxt")
  const express = require("express")
  const app = express()
  
  const nuxt = new Nuxt({ buildDir: "nuxt", dev: false })
  
  function handleRequest(req, res) {
    res.setHeader('Cache-Control', 'private')
    return new Promise((resolve, reject) =&gt; {
      nuxt.render(req, res, promise =&gt; {
        promise.then(resolve).catch(reject)
      })
    })
  }
  
  app.use(handleRequest)
  
  exports.ssr = functions.https.onRequest(app)
  </code></pre>
  
  <p>Expected behavior is that sw.js working fine when I run the app with <code>firebase serve</code> and <code>firebase deploy</code>.</p>