
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@redhare/http
Advanced tools
# Background Currently Http module code is hardcoded into the template code which will make future update or bug fix infeasible. The Http module code should be extracted into an independent nestjs module. In this way developer can not only update the corr
Currently Http module code is hardcoded into the template code which will make future update or bug fix infeasible. The Http module code should be extracted into an independent nestjs module. In this way developer can not only update the corresponding package when new features are released, but also have an option to choose whether they want to use our module in their project.
yarn install @infra-node-kit/http
It's same with @nestjs/axios. The usage of @nestjs/axios can be found at https://docs.nestjs.com/techniques/http-module.
Axios can be configured with a variety of options to customize the behavior of the HttpService. Besides the AxiosRequestConfig, you can also configure with the following options:
| Option | Description | Type | Default |
|---|---|---|---|
| retryMaxCount | max retry count when can't get response. | Number | 1 |
| retryDelay | retry delay | Number | 500 (ms) |
| concurrency | concurrency limit. | Number | Infinity |
| skipPaths | the paths which the log is not required | string[] | [] |
| skipBodyPaths | Whether to hide the body field in the log | boolean | false |
| skipHeadersPaths | Whether to hide the headers field in the log | boolean | false |
The path rule can reference to path-to-regexp
Besides path-to-regexp rules you can use * to match all the paths.
HttpModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
timeout: configService.get('HTTP_TIMEOUT'),
maxRedirects: configService.get('HTTP_MAX_REDIRECTS'),
retryMaxCount: 3,
retryDelay: 1000
}),
inject: [ConfigService],
});
If you want to use a lot of servers, you can create a module for each server which can customize the behavior of the HttpService.
demo:
// server 1
@Module({
controllers: [],
imports: [
HttpModule.register({
baseURL: 'https://api.rap.shopee.io/app/mock/110',
concurrency: 1,
}),
],
providers: [Server1Service],
exports: [Server1Service],
})
export class Server1Module {}
// server 2, have different configurations
@Module({
controllers: [],
imports: [
HttpModule.register({
baseURL: 'https://api.rap.shopee.io/app/mock/120',
timeout: 5000,
concurrency: 1,
}),
],
providers: [Server2Service],
exports: [Server2Service],
})
export class Server2Module {}
// Biz modules can combine these modules
@Module({
imports: [
Server1Module,
Server2Module
],
})
export class BizModule {}
Get more information about
rap: link
First import HttpModule.
import { HttpModule } from '@infra-node-kit/http'
import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
@Module({
imports: [HttpModule.register({ concurrency: 1000 })],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Next, get the method request from the instance of HttpService. After that, hava fun with rapper.
import { NestFactory } from '@nestjs/core'
import { HttpService } from '@infra-node-kit/http'
import { AppModule } from './app.module'
import { overrideFetch } from './rapper'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const httpService = app.get(HttpService)
overrideFetch(async ({ url, method, params }) => {
try {
const response = await httpService.request({
baseURL: 'https://api.rap.shopee.io/app/mock/110',
method,
url,
data: params,
})
return response.data
} catch (error) {
return Promise.reject(error)
}
})
await app.listen(3000)
}
bootstrap()
import { fetch } from '../../rapper'
@Controller('example')
export class ExampleController {
@Get('getTestRap')
async getTestRap(): Promise<string> {
return await fetch['GET/test/get']({})
}
}
provide the following methods:
return an AxiosResponse
configs:
<string><string><string><boolean>, defalut is false<boolean>, defalut is falseaxiosRef is provided. You can use it to intercept requests or specify config defaults that will be applied to every request. But please use the above method to send request, it will loss of concurrency if you send request by axiosRef directly.
FAQs
# Background Currently Http module code is hardcoded into the template code which will make future update or bug fix infeasible. The Http module code should be extracted into an independent nestjs module. In this way developer can not only update the corr
We found that @redhare/http demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.