@centricle/rtfm 1.0.0 → 1.0.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/lib/serve.js +10 -2
- package/package.json +1 -1
package/lib/serve.js
CHANGED
|
@@ -50,8 +50,16 @@ function serve(dir, flags) {
|
|
|
50
50
|
res.writeHead(200, { 'Content-Type': mimeType });
|
|
51
51
|
fs.createReadStream(filePath).pipe(res);
|
|
52
52
|
} else {
|
|
53
|
-
//
|
|
54
|
-
|
|
53
|
+
// For resource files (.md, .css, .js, etc.), return 404 if not found
|
|
54
|
+
// SPA fallback only applies to navigation routes (no extension or .html)
|
|
55
|
+
const ext = path.extname(url.pathname).toLowerCase();
|
|
56
|
+
const isResourceFile = ext && ext !== '.html';
|
|
57
|
+
|
|
58
|
+
if (isResourceFile) {
|
|
59
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
60
|
+
res.end('Not Found');
|
|
61
|
+
} else if (fs.existsSync(indexPath)) {
|
|
62
|
+
// SPA fallback: serve index.html for navigation routes
|
|
55
63
|
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
56
64
|
fs.createReadStream(indexPath).pipe(res);
|
|
57
65
|
} else {
|