nestjs

Can't send API requests on production heroku app

独自空忆成欢 提交于 2020-04-18 03:49:25
问题 I deployed an app in Heroku which has an API written in Nest.js, Vue.js UI and PostgreSQL database. These are the steps I took to build and deploy everything. In my vue directory I ran vue-cli-service build in vue.config.js I specified my proxy and outputDir as follows: outputDir: path.resolve(__dirname, "../ea-blog-api/public"), devServer: { proxy: "https://game-bible.herokuapp.com" }, navigating to ea-blog-api my file structure looks like so public folder contains the compiled output of the

API requests returning errors trying to access NestJS backend from Angular frontend

隐身守侯 提交于 2020-04-17 22:57:11
问题 When making an API call to my NestJS app I'm receiving the following errors. core.js:6185 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: " https://localhost:3333/api/product-index ", ok: false, …} and GET https://localhost:3333/api/product-index net::ERR_SSL_PROTOCOL_ERROR From looking into Nest, Angular and NGXS individually and the suggested ways to go about things I have everything set up properly. The only thing I could think to do was tinker

NestJS Interceptors: Unable to set HTTP Headers on outgoing requests

会有一股神秘感。 提交于 2020-04-16 03:05:33
问题 I am writing APIs in NestJS which have a set of common headers. I decided to use interceptors in order to append headers to outgoing requests. The headers do not get appended to the request and hence the request keep on failing. Interceptor import * as utils from '../utils/utils'; import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; import { HEADERS } from '../middlewares/headers.constant'; import { Observable } from 'rxjs'; import { Request } from

How to unit test Controller and mock @InjectModel in the Service constructor

折月煮酒 提交于 2020-04-11 05:01:49
问题 I am getting issues while unit testing my controller and getting an error "Nest can't resolve dependencies of my service". For maximum coverage I wanted to unit test controller and respective services and would like to mock external dependencies like mongoose connection. For the same I already tried suggestions mentioned in the below link but didn't find any luck with that: https://github.com/nestjs/nest/issues/194#issuecomment-342219043 Please find my code below: export const deviceProviders

NestJS enable cors in production

依然范特西╮ 提交于 2020-04-09 06:40:20
问题 I've enabled CORS in my NestJS app following the official tutorial, so my main.ts looks like the following: import { FastifyAdapter, NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule, new FastifyAdapter(), { cors: true }); await app.listen(3000); } bootstrap(); and it works when I run the application using npm run start:dev . However when I try to first compile the application using npm run

Best practice to use config service in NestJS Module

旧街凉风 提交于 2020-03-22 07:09:29
问题 I want to use environment variables to configure the HttpModule per module, from the docs I can use the configuration like this: @Module({ imports: [HttpModule.register({ timeout: 5000, maxRedirects: 5, })], }) But I don't know what is the best practice to inclue a baseURL from environment vairable (or a config service), for example like this: @Module({ imports: [HttpModule.register({ baseURL: this.config.get('API_BASE_URL'), timeout: 5000, maxRedirects: 5, })], The this.config is undefined

Use socket client with NestJs microservice

ⅰ亾dé卋堺 提交于 2020-03-05 04:14:10
问题 I started working with NestJs recently and got stock while trying to test my NestJs microservices app using a TCP client Is it possible to trigger an @EventPattern or @MessagePattern() using a non-nest app? When trying this method the the socket client just stuck on trying to connect . Any ideas? Thanks. 回答1: Update Feb 2020 Since nest v6.6.0, it has become easier to integrate external services with a message de/serializer. Have a look at the corresponding PR. Original Answer You have to set

How to use Jest to mock winston logger instance encapsulated in service class

时光总嘲笑我的痴心妄想 提交于 2020-03-05 04:06:13
问题 I am trying to mock a winston.Logger instance that is encapsulated within a service class created with NestJS. I have included my code below. I cannot get the mocked logger instance to be triggered from within the service class. Can anyone explain where I am going wrong? import * as winston from 'winston'; import { loggerOptions } from '../logger/logger.config'; import { LoggingService } from '../logger/logger.service'; const logger: winston.Logger = winston.createLogger(loggerOptions); //

NestJs JWT Authentication returns 401

雨燕双飞 提交于 2020-03-05 04:01:54
问题 I have implemented a jwt authentication in nestJs. However whenever I attempt to authenticate using the following authorization headers: Bearer <token> or JWT <token> I got 401. These are my authentication files @Injectable() export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') { constructor(private readonly authService: AuthService) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), secretOrKey: `${process.env.SECRET}`, }); } async validate(payload: Credentials

How to mock third party library using jest

半城伤御伤魂 提交于 2020-02-25 09:48:30
问题 I am developing a node.js application using nestjs I have a class called LoggerService as below export class LoggerService { private logger: Rollbar; constructor() { this.logger = this.setupLogger(); } critical(...args: Array<string | Error | object | Date | any[]>) { this.logger.error(...args); } private setupLogger(): Rollbar { if (this.logger == null) { this.logger = new Rollbar({ accessToken: 'token', environment: 'dev', captureUncaught: true, captureUnhandledRejections: true, }); }