@openworkers/adapter-static 0.1.3 → 0.1.5

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/index.js +18 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -48,9 +48,9 @@ await adapt({
48
48
 
49
49
  ```
50
50
  dist/
51
- ├── worker.js # Worker serving files via ASSETS binding
52
- ├── assets/ # Static files
53
- └── routes.js # Route manifest
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,33 @@ 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,
54
- static: staticFiles.map((f) => '/' + f),
55
- prerendered: [],
65
+ // Static: only non-HTML files (robots.txt, favicon.ico, etc.)
66
+ // HTML files are in prerendered to avoid duplication
67
+ static: nonHtmlFiles.map((f) => '/' + f),
68
+ // Prerendered: HTML files without .html extension
69
+ // Requests with .html extension will match via fallback routing
70
+ prerendered: prerenderedRoutes,
56
71
  functions: [],
57
72
  // If fallback is set, worker handles all unmatched routes (SPA mode)
58
73
  ssr: fallback ? ['/*'] : []
59
74
  };
60
75
 
61
- writeFileSync(
62
- join(out, '_routes.json'),
63
- JSON.stringify(manifest, null, 2)
64
- );
76
+ writeFileSync(join(out, '_routes.json'), JSON.stringify(manifest, null, 2));
65
77
 
66
78
  // Bundle worker with esbuild (use _routes.json for ROUTES alias)
67
79
  await build({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openworkers/adapter-static",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Static site adapter for OpenWorkers",
5
5
  "keywords": [
6
6
  "adapter",