Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@fresh8/nestjs-grpc-transport
Advanced tools
GRPC transport layer for the NestJS framework.
npm install @fresh8/nestjs-grpc-transport --save
Create your protobuf definition sample.proto
:
syntax = "proto3";
package sample;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
Generate your Typescript interfaces using rxjs-grpc.
./node_modules/.bin/rxjs-grpc -o grpc-namespaces.ts *.proto
Create your first controller. The @rpc
decorator provides some metadata needed by Nest, and takes care of providing an Observable for rxjs-grpc.
import { Controller } from '@nestjs/common'
import { rpc } from '@fresh8/nestjs-grpc-transport'
import { sample } from './grpc-namespaces'
@Controller()
export default class TestController {
/**
* sayHello RPC method
*/
@rpc
async sayHello(request: sample.HelloRequest): Promise<sample.HelloReply> {
const res = await this.someAsyncThing()
return { message: `Hello ${request.name}: ${res}` }
}
/**
* Some dummy async method. This might be a call to a database in
* a proper application.
*/
someAsyncThing() {
return Promise.resolve(`:)`)
}
}
Create your GRPC server and provide it to your NestJS application.
import { Module } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { createServer } from '@fresh8/nestjs-grpc-transport'
import { sample } from './grpc-namespaces'
import { TestController } from './test-controller'
/**
* Example application
*/
@Module({
controllers: [TestController]
})
export class ApplicationModule {}
/**
* Create a nest application that runs over GRPC.
*/
const app = NestFactory.createMicroservice(ApplicationModule, {
strategy: createServer<sample.ServerBuilder>({
host: '0.0.0.0',
port: 50051,
protoPath: `path/to/sample.proto`,
packageName: 'sample',
serviceName: 'Greeter'
})
})
/**
* Start your app as normal.
*/
app.listen(() => {
console.log('GRPC server running on 0.0.0.0:50051')
})
A simple example project is provided here.
Nestjs itself catches and handles exceptions as part of its Exception Filters feature. nestjs-grpc-transport
only transforms it to the format expected by rxjs-grpc
.
To the best of our understanding this implies:
@nestjs/microservices/RpcException
will be reported as Internal
error (code 13).Internal
simply throw a new RpcException with the following property:
code : number
: The exception code. Defaults to 13
.message : string
: An additional message. Defaults to "Internal Server Error"FAQs
GRPC transport layer for the NestJS framework
We found that @fresh8/nestjs-grpc-transport demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.