Skip to content

Commit

Permalink
Hide dotfiles and 404 on empty dir
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Jan 2, 2025
1 parent b0e8116 commit f8f2cc0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const serveData: RequestHandler = (req, res, next) => {
const stream = send(req, matches[1] || '', {
index: false,
root: 'data',
dotfiles: 'allow',
});
stream.on(
'directory',
Expand All @@ -107,8 +106,10 @@ const serveData: RequestHandler = (req, res, next) => {
// Print directory listing
readdir(path, (err, list) => {
if (err) return this.error(500, err);
const filtered = list.filter((file) => !file.startsWith('.'));
if (filtered.length === 0) return this.error(404);
res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
res.end(`${list.join('\n')}\n`);
res.end(`${filtered.join('\n')}\n`);
});
},
);
Expand Down

0 comments on commit f8f2cc0

Please sign in to comment.