From f8f2cc017808d185c890bcf89bbe3f3794fe4929 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 2 Jan 2025 14:37:30 -0700 Subject: [PATCH] Hide dotfiles and 404 on empty dir --- rsbuild.config.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 6af59df5f..3969a346f 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -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', @@ -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`); }); }, );