I want to add an endpoint that would simplify development/testing. At the same time, this endpoint is not needed in production. Coming from Java world, there has always been an out of the box solution (eg with profiles), but I didn't find anything like that in the NestJS documentation.
Quastion: Is there a way to implement an endpoint in NestJS that would not be available if the app is built for production use?
A few options depending on your use-case:
Do you have an auth or role based access control scheme? Auth? NestJS has some Auth middleware that might help with this, but might be too heavyweight if this is a one-off: tutorial
One fast and loose way to do this would be to return 404 based on an environment variable. Set the env var differently in your dev servers than production.
if(process.env.ENV_VAR === 'production') {
throw new HttpException('Not Found', HttpStatus.NOT_FOUND)
}