spa-ssi 0.0.10 → 0.0.11

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/package.json +1 -1
  2. package/serve.js +9 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spa-ssi",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Single Page App / Server Side Include Simple File Web Server",
5
5
  "keywords": [
6
6
  "single-page-app",
package/serve.js CHANGED
@@ -66,9 +66,16 @@ class SimpleHTTPRequestHandler {
66
66
 
67
67
  // If requested .html doesn't exist → fallback to root index.html (SPA mode)
68
68
  if ((!stat || !stat.isFile()) && pathname.endsWith(".html")) {
69
+ if(pathname.endsWith(".html")){
70
+ filepath = path.join(this.rootDir, "index.html");
71
+ }else{
72
+ res.writeHead(404, { "Content-Type": "text/plain" });
73
+ res.statusCode = 404;
74
+ res.end(`404 Not Found: ${filepath} \n`);
75
+ return;
76
+ }
69
77
 
70
78
 
71
- filepath = path.join(this.rootDir, "index.html");
72
79
  }
73
80
 
74
81
  // Read file
@@ -86,6 +93,7 @@ class SimpleHTTPRequestHandler {
86
93
  res.end(content);
87
94
 
88
95
  } catch (err) {
96
+ res.statusCode = 404;
89
97
  res.writeHead(404, { "Content-Type": "text/plain" });
90
98
  res.end(`404 Not Found: ${JSON.stringify(err, null, 2)} \n`);
91
99
  }