// app.module.ts
import { Module } from '@nestjs/common';
import { HttpModule } from 'nestjs-undici';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
HttpModule.register({
headers: {
'my-header': `foo-bar`,
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
// app.service.ts
import { lastValueFrom } from 'rxjs';
import { Injectable } from '@nestjs/common';
import { HttpService } from 'nestjs-undici';
@Injectable()
export class AppService {
constructor(private httpService: HttpService) {}
public fetchExternalInfo = async () => {
const baseURL = 'https://api.github.com';
try {
const result = this.httpService.request(
`${baseURL}/repos/hebertcisco/undici`,
);
const response = await lastValueFrom(result);
return response.body.json();
} catch (error) {
throw error;
}
};
}
docker-compose up dev
docker-compose up -d prod
npm install && npm run build
npm run prepare:enviroment
npm run dev
or
npm run dev:test
npm run start
or
npm run start:prod