c64-ready 0.6.0 → 0.6.2
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/bin/headless.mjs +0 -0
- package/bin/serve.mjs +27 -22
- package/package.json +1 -1
package/bin/headless.mjs
CHANGED
|
File without changes
|
package/bin/serve.mjs
CHANGED
|
@@ -62,15 +62,16 @@ const hostname = bindAll ? '0.0.0.0' : '127.0.0.1';
|
|
|
62
62
|
// ---------------------------------------------------------------------------
|
|
63
63
|
// Locate the built dist/ directory
|
|
64
64
|
// ---------------------------------------------------------------------------
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
65
|
+
// Vite builds to dist/ with base '/c64-ready/'.
|
|
66
|
+
// The real app entry point is dist/index.html — assets are at dist/assets/*.
|
|
67
|
+
// dist/c64-ready/ is just the public/c64-ready/ static folder copied verbatim;
|
|
68
|
+
// it is NOT the built app.
|
|
68
69
|
const DIST_DIR = join(PKG_ROOT, 'dist');
|
|
69
|
-
const
|
|
70
|
+
const APP_ENTRY = join(DIST_DIR, 'index.html');
|
|
70
71
|
|
|
71
|
-
if (!existsSync(
|
|
72
|
+
if (!existsSync(APP_ENTRY)) {
|
|
72
73
|
console.error(
|
|
73
|
-
`Error: built player not found at ${
|
|
74
|
+
`Error: built player not found at ${APP_ENTRY}\n` +
|
|
74
75
|
`Run \`npm run build\` inside the c64-ready package first, or install a published release.`,
|
|
75
76
|
);
|
|
76
77
|
process.exit(1);
|
|
@@ -104,15 +105,27 @@ const server = createServer((req, res) => {
|
|
|
104
105
|
// Strip query string and decode URI
|
|
105
106
|
let urlPath = decodeURIComponent((req.url ?? '/').split('?')[0]);
|
|
106
107
|
|
|
107
|
-
//
|
|
108
|
-
if (
|
|
109
|
-
urlPath
|
|
108
|
+
// Route the app root: /, /c64-ready, /c64-ready/ → dist/index.html
|
|
109
|
+
if (
|
|
110
|
+
urlPath === '/' ||
|
|
111
|
+
urlPath === '/c64-ready' ||
|
|
112
|
+
urlPath === '/c64-ready/'
|
|
113
|
+
) {
|
|
114
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
115
|
+
createReadStream(APP_ENTRY).pipe(res);
|
|
116
|
+
return;
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
//
|
|
113
|
-
|
|
119
|
+
// All other requests are resolved against dist/ directly.
|
|
120
|
+
// Vite bakes base='/c64-ready/' into all asset URLs, so strip that prefix
|
|
121
|
+
// before resolving so the path maps into dist/ correctly:
|
|
122
|
+
// /c64-ready/assets/index-xxx.js → dist/assets/index-xxx.js
|
|
123
|
+
// /c64.wasm → dist/c64.wasm
|
|
124
|
+
const stripped = urlPath.startsWith('/c64-ready/') ? urlPath.slice('/c64-ready/'.length) : urlPath;
|
|
125
|
+
const relative = stripped.startsWith('/') ? stripped.slice(1) : stripped;
|
|
114
126
|
const filePath = resolve(DIST_DIR, normalize(relative));
|
|
115
127
|
|
|
128
|
+
// Path traversal guard
|
|
116
129
|
if (!filePath.startsWith(DIST_DIR)) {
|
|
117
130
|
res.writeHead(403);
|
|
118
131
|
res.end('Forbidden');
|
|
@@ -120,22 +133,14 @@ const server = createServer((req, res) => {
|
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
if (!existsSync(filePath) || !statSync(filePath).isFile()) {
|
|
123
|
-
// SPA fallback
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
127
|
-
createReadStream(fallback).pipe(res);
|
|
128
|
-
} else {
|
|
129
|
-
res.writeHead(404);
|
|
130
|
-
res.end('Not found');
|
|
131
|
-
}
|
|
136
|
+
// SPA fallback for any unmatched path
|
|
137
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
138
|
+
createReadStream(APP_ENTRY).pipe(res);
|
|
132
139
|
return;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
const ext = extname(filePath).toLowerCase();
|
|
136
143
|
const mime = MIME[ext] ?? 'application/octet-stream';
|
|
137
|
-
|
|
138
|
-
// WASM requires correct MIME — browsers reject it otherwise
|
|
139
144
|
res.writeHead(200, { 'Content-Type': mime });
|
|
140
145
|
createReadStream(filePath).pipe(res);
|
|
141
146
|
});
|