nestjs

How to correctly build NestJS app for production with node_modules dependencies in bundle?

陌路散爱 提交于 2020-02-21 13:46:28
问题 After nest build or nest build --webpack dist folder does not contain all required modules and I got Error: Cannot find module '@nestjs/core' when trying to run node main.js . I could not find any clear instructions on https://docs.nestjs.com/ on how to correctly build app for production, so maybe I missed something? 回答1: Out of the box, nest cli does not support including the node_modules dependencies into the dist bundle. However, there are some community examples of custom webpack configs

NestJs - Unable to get user context in RolesGuard

给你一囗甜甜゛ 提交于 2020-02-21 10:50:11
问题 I'm using NestJS as the framework for a client API. Within the framework we are using a pretty standard Passport/JWT auth infrastructure that is working fine. Our AuthGuard is firing when the bearer token is found and, in secure API endpoints, I can inject the HTTP context via '@Res() request' and get access to the 'request.user' property which contains the payload of my Jwt token. On top of this we are attempting to implement a 'RolesGuard' in a very similar fashion to the sample code

NestJs - Unable to get user context in RolesGuard

╄→гoц情女王★ 提交于 2020-02-21 10:49:08
问题 I'm using NestJS as the framework for a client API. Within the framework we are using a pretty standard Passport/JWT auth infrastructure that is working fine. Our AuthGuard is firing when the bearer token is found and, in secure API endpoints, I can inject the HTTP context via '@Res() request' and get access to the 'request.user' property which contains the payload of my Jwt token. On top of this we are attempting to implement a 'RolesGuard' in a very similar fashion to the sample code

Not able to call Service inside WebSocket listener in Nestjs

霸气de小男生 提交于 2020-02-06 16:21:28
问题 I have implemented WebSockets in Nestjs using below method and one of the requirement is that I need to update the db once I receive any message from websocket server. In order to do that I have done the below code but getting error like this: But if I call the same method inside any other controller method it works fine(check /test1). Only when I call it from websocket listener I'm getting this error. Even if I call simple method from same controller to just print some log, I'm getting the

How to use findOneAndUpdate using an aggregated query in mongoDB?

依然范特西╮ 提交于 2020-02-06 08:01:08
问题 I am using nestJS as a backend connected with MongoDB. I am able to access a nested array in my schema which is: { "id": "productId", "name": "productName", "price": "productPrice", "Categories": [ { "_id": "catId", "name": "catName", "Subcategories": [ { "_id": "subcatId", "name": "subcatName" }, { "_id": "subcatId", "name": "subcatName" }, ] }, { "_id": "catId", "name": "catName", "Subcategories": [ { "_id": "subcatId", "name": "subcatName" }, { "_id": "subcatId", "name": "subcatName" }, ]

NestJS Using ConfigService with TypeOrmModule

允我心安 提交于 2020-02-02 13:38:30
问题 I set up a ConfigService as described in docs https://docs.nestjs.com/techniques/configuration How can I use this service with the the TypeOrmModule? TypeOrmModule.forRoot({ type: 'mysql', host: 'localhost', port: 3306, username: 'root', password: 'root', database: 'test', entities: [__dirname + '/**/*.entity{.ts,.js}'], synchronize: true, }), 回答1: See https://docs.nestjs.com/techniques/database Async Configuration chapter import {ConfigService} from './config.service'; import {Module} from '

What is the nestjs error handling approach (business logic error vs. http error)?

我与影子孤独终老i 提交于 2020-02-01 03:12:40
问题 While using NestJS to create API's I was wondering which is the best way to handle errors/exception. I have found two different approaches : Have individual services and validation pipes throw new Error() , have the controller catch them and than throw the appropriate kind of HttpException ( BadRequestException , ForbiddenException etc..) Have the controller simply call the service/validation pipe method responsible for handling that part of business logic, and throw the appropriate

TypeORM - never return the password from the database when fetching a user

蓝咒 提交于 2020-01-30 08:20:05
问题 I created a REST API using NestJs with TypeORM. Basically this is my user entity @Entity('User') export class User extends BaseEntity { @PrimaryGeneratedColumn() public id: number; @Column({ unique: true }) public username: string; public passwordHash: string; } When fetching users from the database the sensitive password information get returned too. But I only need the password field for the sign in process. So when calling the service for signing in I compare the password hash from the

TypeORM - never return the password from the database when fetching a user

旧街凉风 提交于 2020-01-30 08:18:08
问题 I created a REST API using NestJs with TypeORM. Basically this is my user entity @Entity('User') export class User extends BaseEntity { @PrimaryGeneratedColumn() public id: number; @Column({ unique: true }) public username: string; public passwordHash: string; } When fetching users from the database the sensitive password information get returned too. But I only need the password field for the sign in process. So when calling the service for signing in I compare the password hash from the

How to return an image file correctly using nest.js?

你说的曾经没有我的故事 提交于 2020-01-25 08:57:33
问题 I'm trying to return the requested image file. My client is downloading the file, but I can't display it because it's an invalid png file. If I open the stored file tmpFile.png , I can see it correctly. So probably the problem is on how I'm sending it back to the client asking for it. // This is my controller async getFile(@Param('bucketname') bucketName: string, @Param('filename') fileName: string) { return await this.appService.getFile(bucketName, fileName); // This is the function called