From 641b93a89e012fe1d924793c81da739cc7f67da8 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Mon, 11 Nov 2024 17:41:10 +0900 Subject: [PATCH] feat(dev-server): exclude files in `public` dir --- packages/dev-server/e2e/e2e.test.ts | 5 +++++ packages/dev-server/e2e/public/hono-logo.png | Bin 0 -> 8485 bytes packages/dev-server/src/dev-server.ts | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/dev-server/e2e/public/hono-logo.png diff --git a/packages/dev-server/e2e/e2e.test.ts b/packages/dev-server/e2e/e2e.test.ts index 59d36bd..2ead110 100644 --- a/packages/dev-server/e2e/e2e.test.ts +++ b/packages/dev-server/e2e/e2e.test.ts @@ -101,3 +101,8 @@ test('Should set `cf` properties', async ({ page }) => { expect(res?.ok()).toBe(true) expect(await res?.json()).toEqual({ cf: true }) }) + +test('Should return files in the public directory', async ({ page }) => { + const res = await page.goto('/hono-logo.png') + expect(res?.status()).toBe(200) +}) diff --git a/packages/dev-server/e2e/public/hono-logo.png b/packages/dev-server/e2e/public/hono-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..562a3b50076883af00864a85f4cc8c69e2a83b95 GIT binary patch literal 8485 zcmZ{KbzD@@*7nfdAw5IrfYi_oAgwggjl{sn5Hpmd;4pMar!-0lA`OCcH`0g_LpvZS zBB`I=d%t_{?|Z*@pWiuq?e#p*T5GR;{y2Y}SOa|xDsnb*002OxrKxW8XNLd1Ns0eF zp=(=?e5-2nj55dgsD9~XKL0C)lc01oT{0J&@c z;Ff3JJ41y(fPu4x7F5At@%8nT6BYIM_ZRV(5J7oA78Qd+p`s9RQE_qMKMY}?K%}ojfH2aB_n$%jZya@J zADB17(-(n4g8s&Ja6~=vy~o4zH_^YxKkIZ3K>Q~Y(&t~>`m;gNzlf-q2t@S%C-X(X z{}o? z|D2&Bxq|4w-v>qVAreVT0Dy~GOI^hz0PoP2BAH_#@K>;%fB7wXO;s8$eAruBns8cB zQC>KjX_Od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97fkS1MJ{ki&hFu-%ibs+r{SN+hRZI+uqP(=&D)QzjHi#I|Nrs zTzdg=lDC?Pk!&q<{$NNtu6@jJ^^g`>(RiZ3=-8@G9GEWvd5s)#o;{l}H&9z|O}0$A zwb6wXduZA<5!|uwsKF-ltk;jtxTs02i+49se~v5d9#H@Cp~Gi=0|8Y=S{@?R9tgL= z+W?!72{=%wx#yx?K8vHRN;kBKO4;C6O58e>ufgi9Dl{przN2f_D)nU>YxKw$Y$#>Q z9D;_uacFpmHprHecCufW>X#9|L>(PJrhn)_mzw)g4L1CKN`;r)pglXka^moMp`czs zwR`u-O~pBILUe1lBQ~~^@N46ABN6SVNa|k;Vskxy{)o8Vv`|u1k#t-$kV#=S!C7d>mwTxBwMeT&~a0@Mxv|R*NJ}mEnMjg#1iSaa0?c? z)e&_QKOD@3?gUJrGv|yNnqAGoM-_r$WSi4ZxI^ygqA0 z1hM@*_*fwiG(cfP@)f?i+G9W_)_H~{ZIv?$MZ|GsB=-*(#Kn7e)i&y6?6|x|Z7bI* yMc?nbuktA$E1 { async function createMiddleware(server: ViteDevServer): Promise { return async function ( @@ -71,8 +77,18 @@ export function devServer(options?: DevServerOptions): VitePlugin { res: http.ServerResponse, next: Connect.NextFunction ): Promise { - const exclude = options?.exclude ?? defaultOptions.exclude + if (req.url) { + const filePath = path.join(publicDirPath, req.url) + try { + if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { + return next() + } + } catch { + // do nothing + } + } + const exclude = options?.exclude ?? defaultOptions.exclude for (const pattern of exclude) { if (req.url) { if (pattern instanceof RegExp) {