@webjsdev/server 0.8.42 → 0.8.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/dev.js +15 -4
package/package.json
CHANGED
package/src/dev.js
CHANGED
|
@@ -1825,9 +1825,14 @@ async function handleCore(req, ctx) {
|
|
|
1825
1825
|
return invokeAction(state.actionIndex, actMatch[1], actMatch[2], req, onActionError, allowedOrigins);
|
|
1826
1826
|
}
|
|
1827
1827
|
|
|
1828
|
-
// Static: /public
|
|
1829
|
-
|
|
1830
|
-
|
|
1828
|
+
// Static: /public/*, plus a small set of ROOT assets that must serve at the
|
|
1829
|
+
// site root even though they live under public/. A service worker registered
|
|
1830
|
+
// at /sw.js scopes to the origin root, so it MUST serve at / (not
|
|
1831
|
+
// /public/sw.js), and so must its offline fallback. Same remap shape as the
|
|
1832
|
+
// /favicon.ico special-case below. (#830)
|
|
1833
|
+
const ROOT_ASSETS = { '/sw.js': '/public/sw.js', '/offline.html': '/public/offline.html' };
|
|
1834
|
+
if (path.startsWith('/public/') || path === '/favicon.ico' || path in ROOT_ASSETS) {
|
|
1835
|
+
const p = path === '/favicon.ico' ? '/public/favicon.ico' : (ROOT_ASSETS[path] || path);
|
|
1831
1836
|
const abs = join(appDir, p);
|
|
1832
1837
|
// Containment check. `join` normalises `..` segments, so a path
|
|
1833
1838
|
// like `/public/%2E%2E/secret/x.svg` decodes (after URL parsing,
|
|
@@ -1843,7 +1848,13 @@ async function handleCore(req, ctx) {
|
|
|
1843
1848
|
return new Response(null, { status: 404 });
|
|
1844
1849
|
}
|
|
1845
1850
|
// A `?v=<hash>` public asset is content-addressed -> immutable (#243).
|
|
1846
|
-
if (await exists(abs))
|
|
1851
|
+
if (await exists(abs)) {
|
|
1852
|
+
const res = await fileResponse(abs, { dev, immutable: versioned });
|
|
1853
|
+
// A worker served below its registration path only controls that subtree
|
|
1854
|
+
// unless the response opts it up to the root scope. (#830)
|
|
1855
|
+
if (path === '/sw.js') res.headers.set('Service-Worker-Allowed', '/');
|
|
1856
|
+
return res;
|
|
1857
|
+
}
|
|
1847
1858
|
}
|
|
1848
1859
|
|
|
1849
1860
|
// User source modules (served as ES modules, with action-file rewriting).
|