|
1 | 1 | #!/usr/bin/env node |
| 2 | +/* eslint-env node */ |
2 | 3 |
|
3 | 4 | const http = require('http'); |
4 | 5 | const https = require('https'); |
@@ -68,9 +69,8 @@ proxy.on('error', (err, req, res) => { |
68 | 69 | }); |
69 | 70 |
|
70 | 71 | // Modify proxy request headers |
71 | | -proxy.on('proxyReq', (proxyReq, req, res) => { |
| 72 | +proxy.on('proxyReq', (proxyReq, req) => { |
72 | 73 | // Transform localhost:8000 to appear as phcode.dev domain |
73 | | - const originalHost = req.headers.host; |
74 | 74 | const originalReferer = req.headers.referer; |
75 | 75 | const originalOrigin = req.headers.origin; |
76 | 76 |
|
@@ -293,7 +293,18 @@ const server = http.createServer((req, res) => { |
293 | 293 | console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}${config.logIp ? ` (${clientIp})` : ''}`); |
294 | 294 | } |
295 | 295 |
|
296 | | - serveStaticFile(req, res, filePath); |
| 296 | + // Handle directory requests without trailing slash |
| 297 | + fs.stat(filePath, (err, stats) => { |
| 298 | + if (err) { |
| 299 | + serveStaticFile(req, res, filePath); |
| 300 | + } else if (stats.isDirectory() && !parsedUrl.pathname.endsWith('/')) { |
| 301 | + // Redirect to URL with trailing slash for directories |
| 302 | + res.writeHead(301, { 'Location': req.url + '/' }); |
| 303 | + res.end(); |
| 304 | + } else { |
| 305 | + serveStaticFile(req, res, filePath); |
| 306 | + } |
| 307 | + }); |
297 | 308 | }); |
298 | 309 |
|
299 | 310 | // Parse arguments and start server |
|
0 commit comments