fix(vite): pathname treated as static file (#3326)

Fixes https://github.com/denoland/fresh/issues/3322
This commit is contained in:
Marvin Hagemeister
2025-09-03 11:34:19 +02:00
committed by GitHub
parent 717aa32111
commit 08ef05fc1d
3 changed files with 38 additions and 5 deletions
+13 -3
View File
@@ -4,9 +4,13 @@ import { ASSET_CACHE_BUST_KEY } from "fresh/internal";
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
export function devServer(): Plugin[] {
let publicDir = "";
return [
{
name: "fresh:dev_server",
configResolved(config) {
publicDir = config.publicDir;
},
configureServer(server) {
const IGNORE_URLS = /^\/(@(vite|fs|id)|\.vite)\//;
@@ -29,17 +33,23 @@ export function devServer(): Plugin[] {
server.environments.client.moduleGraph.urlToModuleMap.has(
url.pathname,
) ||
server.environments.ssr.moduleGraph.urlToModuleMap.has(
url.pathname,
) ||
url.pathname === "/.well-known/appspecific/com.chrome.devtools.json"
) {
return next();
}
// Check if it's a static file first
if (url.pathname !== "/") {
const ext = path.extname(url.pathname);
if (ext !== "") {
const staticFilePath = path.join(publicDir, url.pathname.slice(1));
try {
const stat = await Deno.stat(staticFilePath);
if (stat.isFile) {
return next();
}
} catch {
// Ignore
}
const mod = await server.ssrLoadModule("fresh:server_entry");