Route for /__xdn__/cache-manifest.js fails if `fallback` route is defined

export default new Router()
  .prerender(getPrerenderRequests)
  .match('/api/:path*', API_CACHE_HANDLER)
  .match('/category/:name', SSR_CACHE_HANDLER)
  .match('/product/:name', SSR_CACHE_HANDLER)

  .match('/service-worker.js', ({ serviceWorker }) => {
    serviceWorker('dist/service-worker.js')
  })

  // Send requests to static assets in the build output folder `dist`
  .static('dist')

  // Send everything else to the App Shell
  .fallback(({ appShell }) => {
    appShell('dist/index.html')
  })

I have noticed the Prefetcher makes a request to /__xdn__/cache-manifest.js and it is failing with a 500 with the following response:

HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
content-type: application/json
x-request-id: 4a598003-64e2-41a5-a4bb-ecb4079905f3
Date: Mon, 14 Dec 2020 18:38:41 GMT
Connection: keep-alive
Transfer-Encoding: chunked

{"message":"An error occured while running route /__xdn__/cache-manifest.js: appShell is not a function","stack":"TypeError: appShell is not a function\n    at Route.handler (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:12492:3)\n    at Function.__webpack_modules__../node_modules/@xdn/core/router/CacheManifest.js.CacheManifest.fromRouter (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:4651:23)\n    at /Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:8515:92\n    at ResponseWriter.<anonymous> (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:6533:46)\n    at step (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:5517:23)\n    at Object.next (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:5498:53)\n    at /Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:5492:71\n    at new Promise (<anonymous>)\n    at __webpack_modules__../node_modules/@xdn/core/router/ResponseWriter.js.__awaiter (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:5488:12)\n    at ResponseWriter.createResponseAction (/Users/tristanlee/Projects/xdn-org/xdn-examples/xdn-vue-example/.xdn/lambda/routes.js:6528:64)","url":"/__xdn__/cache-manifest.js","route":{"handler":"function (_a) {\n        var cache = _a.cache, setResponseHeader = _a.setResponseHeader, send = _a.send, allowCors = _a.allowCors;\n        cache({\n            edge: {\n                maxAgeSeconds: 60 * 60 * 24 * 365,\n            },\n            browser: {\n                maxAgeSeconds: 60 * 60,\n            },\n        });\n        setResponseHeader('content-type', 'text/javascript');\n        allowCors();\n        send(function () { return \"self.__XDN_CACHE_MANIFEST__=\" + CacheManifest_1.default.fromRouter(router).toJSON(); });\n    }","criteria":{"path":"/__xdn__/cache-manifest.js"}}}
Status: 500, Connect: 0.000895, TTFB: 0.019666, Total: 0.019713%            

After a bit of debugging, it is being handled by .fallback(...) which I don’t believe it should be reaching, but also doesn’t have all of the same properties available that ResponseWriter typically would as appShell is not defined. If I comment out my fallback route, then the route is handled successfully.

We have a fix merged and we will release it soon.

We have just released version 2.32.2 which has the fix for the issue you reported. Please let us know how it works for you.

I updated to the latest version but still see the error. It is reaching my fallback route when it should be hitting a built-in route for the cache manifest:

scurl http://127.0.0.1:3000/__xdn__/cache-manifest.js
HTTP/1.1 500 Internal Server Error
content-type: application/json
x-request-id: c171fe35-bcd4-4ee0-beac-3e91f3d61ebb
x-xdn-status: w=500
x-xdn-t: wt=12
x-xdn-components: w=2.32.2
Date: Tue, 15 Dec 2020 14:17:33 GMT
Connection: keep-alive
Transfer-Encoding: chunked

{"status":"error","message":"(0 , e.appShell) is not a function"}
Status: 500, Connect: 0.000642, TTFB: 0.024239, Total: 0.024286% 

Sorry to hear that - we are looking into it.

Tristan - we have released the fix in v2.33.3. Let me know how it works for you.

I updated to the latest and this is now working correctly. Thanks!

1 Like

Glad to hear it - thank you for confirming that.