Skip to content

Latest grpc-js breaks mali ctx.res.pipe #376

@kirrg001

Description

@kirrg001

Hey!

  TypeError: ctx.res.pipe is not a function
      at execStream (grpc-mali-rep/node_modules/mali/lib/run.js:53:13)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Demo

test.proto

syntax = "proto3";

package myservice.node.grpc.test;

message TestRequest {
  string parameter = 1;
}

message TestReply {
  string message = 1;
}

service TestService {
  rpc MakeUnaryCall (TestRequest) returns (TestReply) {}
}

server.js

const port = process.env.APP_PORT || 28428
const Mali = require('mali');
const express = require('express');
const path = require('path');
const expressApp = express();

async function MakeUnaryCall(ctx) {
  ctx.res = { message: 'Hey' };
}

const maliApp = new Mali(path.join(__dirname, 'test.proto'));

maliApp.use({
  MakeUnaryCall
});

maliApp.start('127.0.0.1:50051');

expressApp.get('/', (req, res) => {
  res.send('OK');
});

expressApp.listen(port, () => {
    console.log(`Listening on port: ${port}`);
});

client.js

const port = process.env.APP_PORT || 30484
const bodyParser = require('body-parser');
const express = require('express');
const grpc = require('@grpc/grpc-js');
const path = require('path');
const app = express();
const PROTO_PATH = path.join(__dirname, 'test.proto');

let client;
let makeUnaryCall;

function runClient() {
  const protoLoader = require('@grpc/proto-loader');
  const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true
  });

  const testProto = grpc.loadPackageDefinition(packageDefinition).myservice.node.grpc.test;
  client = new testProto.TestService('localhost:50051', grpc.credentials.createInsecure());
}

runClient();

app.use(bodyParser.json());

app.get('/', (req, res) => {
  res.send('OK');
});

app.post('/unary-call', (req, res) => {
    client.makeUnaryCall({}, (err, reply) => {
	if (err) {
	    return res.send(err);
	}
	const message = typeof reply.getMessage === 'function' ? reply.getMessage() : reply.message;
	return res.send({ reply: message });
    });
});

app.listen(port, () => {
  console.log(`Listening on port: ${port}`);
});

package.json

{
  "name": "grpc-mali-rep",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@grpc/grpc-js": "^1.10.6",
    "body-parser": "^1.20.2",
    "express": "^4.19.2",
    "mali": "^0.47.1"
  }
}

CURL -X POST http://localhost:30484/unary-call

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions