Skip to content

Commit

Permalink
Merge pull request #25 from douhjs/fix-static-index
Browse files Browse the repository at this point in the history
Return `next()` when index.html not exist in the directory
  • Loading branch information
changchanghwang authored Aug 16, 2023
2 parents df8ad19 + 447452c commit a8fe9c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "douh",
"version": "0.1.2",
"version": "0.1.3",
"description": "http based node.js web server framework",
"author": "changchanghwnag",
"homepage": "https://github.com/douhjs/douh",
Expand Down
8 changes: 6 additions & 2 deletions src/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ export function serveStatic(baseRoute: string) {
if (!exist) {
return next();
}
let stat = fs.statSync(filePath);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
filePath = path.join(filePath, 'index.html');
stat = await asyncFs.stat(filePath);

const exist = fs.existsSync(filePath);
if (!exist) {
return next();
}
}

const data = await asyncFs.readFile(filePath);
Expand Down

0 comments on commit a8fe9c5

Please sign in to comment.