Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@nclabs/rpc-config
Advanced tools
Utilitário NestJS para configuração de rotas e cache em microserviços. Utilido especificamente para projetos nclabs
Utilitário para configuração de rotas e cache em microserviços. Utilido especificamente para projetos nclabs
npm i @nclabs/rpc-config
# Environment variables
...
# Quando compartilhar o mesmo .env, indicar o nome do serviço no
# docker compose para idenficar o serviço correto
SERVICE_NAME=<service_name>
# ##################################################################### #
# REDIS #
# ##################################################################### #
REDIS_HOST=<host>
REDIS_PORT=<port>
REDIS_PASSWORD=<password>
REDIS_DB=0
REDIS_CACHE_DB=0
...
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { RpcConfigModule } from '@nclabs/rpc-config';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { CacherInterceptor } from '@nclabs/rpc-config';
@Module({
imports: [
...
RpcConfigModule.forRoot({
// Opcional - Pode ser omitido quando não for utilizar o cache
cache: {
prefix: process.env.CACHE_PREFIX,
ttl: parseInt(process.env.CACHE_TTL, 10),
logCacheHit: process.env.CACHE_HIT_LOG === 'true',
},
}),
...
],
controllers: [AppController],
providers: [
AppService,
// Opcional - Pode ser omitido quando não for utilizar o cache
{
provide: APP_INTERCEPTOR,
useClass: CacherInterceptor,
},
],
})
export class AppModule {}
// app.controller.ts
import { Action, Event, Rest } from '@nclabs/rpc-config';
@Controller()
export class AppController {
...
/**
*
* REST
*
* Permite que o metodo seja requisitado pela api-gateway.
*
* Na configuração abaixo as rotas GET e POST são permitidas na url:
*
* <base_url>/user-credential/:id
*
* * base_url: http://<host>:<api_port>/<api_prefix>
*
*/
@Rest({
rest: {
methods: ['GET', 'POST'],
path: '/user-credential/:id',
},
cache: {
keys: ['#headers.authorization', "#params.username"],
ttl: 1200, // 20 minutes
},
})
userCredential(@Payload() params: { username: string }): Observable<UserCredential> {
return this.appService.getUserCredential();
}
...
/**
*
* RPC ACTION
*
* Permite que o metodo seja requisitado através de um RPC client.
*
* * Mais informações em:
* https://docs.nestjs.com/microservices/basics#sending-messages
*
*/
@Action({
name: 'get-user-credential',
cache: {
keys: ['#params.apiKey'],
},
})
getTokenFromKey(@Payload() params: { apiKey: string }): Obserable<UserCredential> {
console.log('params', params);
return this.appService.getUserCredential();
}
...
/**
*
* RPC EVENT
*
*
* Permite que o envio de um evento para o método através de um RPC client.
*
* * Mais informações em:
* https://docs.nestjs.com/microservices/basics#publishing-events
*/
@Event({
name: 'user-changed',
})
eventTeste(@Payload() params: UserPayload /* @Ctx() context: NatsContext */): void {
// do something
return;
}
...
}
FAQs
Utilitário NestJS para configuração de rotas e cache em microserviços. Utilido especificamente para projetos nclabs
The npm package @nclabs/rpc-config receives a total of 0 weekly downloads. As such, @nclabs/rpc-config popularity was classified as not popular.
We found that @nclabs/rpc-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.