@openworkers/adapter-static 0.1.3 → 0.1.4
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/README.md +3 -3
- package/index.js +15 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,9 +48,9 @@ await adapt({
|
|
|
48
48
|
|
|
49
49
|
```
|
|
50
50
|
dist/
|
|
51
|
-
├──
|
|
52
|
-
├──
|
|
53
|
-
└──
|
|
51
|
+
├── _worker.js # Worker serving files via ASSETS binding
|
|
52
|
+
├── _routes.json # Route manifest for edge routing
|
|
53
|
+
└── assets/ # Static files
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
## Routing Modes
|
package/index.js
CHANGED
|
@@ -47,21 +47,31 @@ export async function adapt(options = {}) {
|
|
|
47
47
|
const allFiles = listFiles(join(out, 'assets'));
|
|
48
48
|
const staticFiles = allFiles.filter((f) => !isImmutablePath(f, immutable));
|
|
49
49
|
|
|
50
|
+
// Split HTML files and non-HTML files
|
|
51
|
+
const htmlFiles = staticFiles.filter((f) => f.endsWith('.html'));
|
|
52
|
+
const nonHtmlFiles = staticFiles.filter((f) => !f.endsWith('.html'));
|
|
53
|
+
|
|
54
|
+
// Generate prerendered routes (HTML files without .html extension)
|
|
55
|
+
const prerenderedRoutes = htmlFiles.map((f) => {
|
|
56
|
+
const path = '/' + f.replace(/\.html$/, '');
|
|
57
|
+
// Convert /index to / and /foo/index to /foo
|
|
58
|
+
return path.replace(/\/index$/, '/');
|
|
59
|
+
});
|
|
60
|
+
|
|
50
61
|
const manifest = {
|
|
51
62
|
mode,
|
|
52
63
|
fallback,
|
|
53
64
|
immutable,
|
|
65
|
+
// Static: all files with their original names (including .html)
|
|
54
66
|
static: staticFiles.map((f) => '/' + f),
|
|
55
|
-
|
|
67
|
+
// Prerendered: HTML files without .html extension
|
|
68
|
+
prerendered: prerenderedRoutes,
|
|
56
69
|
functions: [],
|
|
57
70
|
// If fallback is set, worker handles all unmatched routes (SPA mode)
|
|
58
71
|
ssr: fallback ? ['/*'] : []
|
|
59
72
|
};
|
|
60
73
|
|
|
61
|
-
writeFileSync(
|
|
62
|
-
join(out, '_routes.json'),
|
|
63
|
-
JSON.stringify(manifest, null, 2)
|
|
64
|
-
);
|
|
74
|
+
writeFileSync(join(out, '_routes.json'), JSON.stringify(manifest, null, 2));
|
|
65
75
|
|
|
66
76
|
// Bundle worker with esbuild (use _routes.json for ROUTES alias)
|
|
67
77
|
await build({
|