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.
Files changed (2) hide show
  1. package/bin/serve.mjs +23 -21
  2. 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
- // When installed as a package the layout is: <pkg>/dist/c64-ready/index.html
66
- // (Vite builds to dist/ with base '/c64-ready/'). When run from the repo
67
- // root the same path applies.
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 PLAYER_DIR = join(DIST_DIR, 'c64-ready');
70
+ const APP_ENTRY = join(DIST_DIR, 'index.html');
70
71
 
71
- if (!existsSync(PLAYER_DIR)) {
72
+ if (!existsSync(APP_ENTRY)) {
72
73
  console.error(
73
- `Error: built player not found at ${PLAYER_DIR}\n` +
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
- // Map '/' → '/index.html'
108
- if (urlPath === '/' || urlPath === '/c64-ready' || urlPath === '/c64-ready/') {
109
- urlPath = '/c64-ready/index.html';
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
- // Resolve against dist root, prevent path traversal
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 — serve the player index for any unknown path under /c64-ready/
124
- const fallback = join(PLAYER_DIR, 'index.html');
125
- if (existsSync(fallback)) {
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
  });
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "retro"
11
11
  ],
12
12
  "license": "MIT",
13
- "version": "0.6.0",
13
+ "version": "0.6.1",
14
14
  "type": "module",
15
15
  "engines": {
16
16
  "node": ">=24.14"