Skip to content

Commit 00d2275

Browse files
authored
fix(fastify): serve index file when it exists
1 parent 117fe43 commit 00d2275

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/loaders/fastify.loader.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,19 @@ export class FastifyLoader extends AbstractLoader {
4343
const renderFn = (req: any, res: any) => {
4444
fs.stat(indexFilePath, (err) => {
4545
if (err) {
46-
const stream = fs.createReadStream(indexFilePath);
47-
if (options.serveStaticOptions?.setHeaders) {
48-
const stat = fs.statSync(indexFilePath);
49-
options.serveStaticOptions.setHeaders(res, indexFilePath, stat);
50-
}
51-
res.type('text/html').send(stream);
52-
} else {
5346
const error = new NotFoundException();
5447
res.status(error.getStatus()).send(error.getResponse());
48+
return;
5549
}
50+
51+
const stream = fs.createReadStream(indexFilePath);
52+
53+
if (options.serveStaticOptions?.setHeaders) {
54+
const stat = fs.statSync(indexFilePath);
55+
options.serveStaticOptions.setHeaders(res, indexFilePath, stat);
56+
}
57+
58+
res.type('text/html').send(stream);
5659
});
5760
};
5861

0 commit comments

Comments
 (0)