Skip to content

Commit

Permalink
fix: handle file not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
vclemenzi committed Mar 20, 2024
1 parent e01b5af commit 491c690
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/server/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ export const createServer = (server: ViteDevServer) => {
if (!req.url) return;

if (!/\.[a-z]+$/.test(req.url)) {
if (!fs.existsSync(`dist${req.url}/index.html`)) return res.end("404");

return res.end(fs.readFileSync(`dist${req.url}/index.html`));
}

const ext = req.url.split(".").pop() || "";

if (!fs.existsSync(`dist${req.url}`)) return res.end("404");

res.setHeader("Content-Type", mime.getType(ext) || "text/plain");
return res.end(fs.readFileSync(`dist${req.url}`));
});
Expand Down

0 comments on commit 491c690

Please sign in to comment.