I'm using @fastify/static
so I could use sendFile in reply of fastify
and that works perfect with Controller like (I should return cause without return files are sending empty)
@Controller()
export class AppController {
@Get('file')
getFileTest(@Res() res: FastifyReply) {
return res.sendFile('index.html');
}
}
but the problem is I need to sendFile in an exception (and all files are sending empty no matter with return or without) (that works with express and not with fastify)
import {
ExceptionFilter,
Catch,
NotFoundException,
ArgumentsHost,
} from '@nestjs/common';
import { FastifyReply } from 'fastify';
@Catch(NotFoundException)
export class NotFoundExceptionFilter implements ExceptionFilter {
catch(exception: NotFoundException, host: ArgumentsHost) {
const response = host.switchToHttp().getResponse<FastifyReply>();
return response.status(200).sendFile('index.html');
//response.status(200).send('text'); //works fine express and fastify
}
}
are there ways to sendFile from and @Catch(NotFoundException)?
route "/" returns index.html
route "file" returns index.html
any else routes are returning empty index.html
A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript starter repository.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
Nest is MIT licensed.