c64-ready 0.6.0 → 0.6.1
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/serve.mjs +23 -21
- package/package.json +1 -1
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,24 @@ 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
|
-
//
|
|
119
|
+
// All other requests are resolved against dist/ directly.
|
|
120
|
+
// e.g. /c64-ready/assets/index-xxx.js → dist/c64-ready/assets/index-xxx.js
|
|
121
|
+
// /c64.wasm → dist/c64.wasm
|
|
113
122
|
const relative = urlPath.startsWith('/') ? urlPath.slice(1) : urlPath;
|
|
114
123
|
const filePath = resolve(DIST_DIR, normalize(relative));
|
|
115
124
|
|
|
125
|
+
// Path traversal guard
|
|
116
126
|
if (!filePath.startsWith(DIST_DIR)) {
|
|
117
127
|
res.writeHead(403);
|
|
118
128
|
res.end('Forbidden');
|
|
@@ -120,22 +130,14 @@ const server = createServer((req, res) => {
|
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
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
|
-
}
|
|
133
|
+
// SPA fallback for any unmatched path
|
|
134
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
135
|
+
createReadStream(APP_ENTRY).pipe(res);
|
|
132
136
|
return;
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
const ext = extname(filePath).toLowerCase();
|
|
136
140
|
const mime = MIME[ext] ?? 'application/octet-stream';
|
|
137
|
-
|
|
138
|
-
// WASM requires correct MIME — browsers reject it otherwise
|
|
139
141
|
res.writeHead(200, { 'Content-Type': mime });
|
|
140
142
|
createReadStream(filePath).pipe(res);
|
|
141
143
|
});
|