I have created a gRPC server in my Node.js app alongside my Express.js server
const server = getServer();
server.bindAsync(
`0.0.0.0:${process.env.HTTP20_ONLY_PORT}`,
grpc.ServerCredentials.createInsecure(),
(err, port) =\> {
if (err) {
console.error(err);
return;
}
console.log(`gRPC server started on port ${port}`);
server.start();
}
);
const getServer = () =\> {
const server = new grpc.Server();
server.addService(dataCalculatorPackage.DataCalculatorService.service, {
PerformanceDataByPlanAndForcesIds:
getPerformanceDataByPlanIdAndForceIdByCall,
} as DataCalculatorServiceHandlers);
return server;
};
It appears that the gRPC server is up and running.
I enabled the HTTP version to 2 and set the HTTP 2.0 Proxy to gRPC only. I added the HTTP20_ONLY_PORT to the environment variables.
For my gRPC client, I am using Nest.js, and I establish the connection with the Azure service URL.
const packageDef = loadSync(path.resolve(\__dirname, PROTO_FILE), {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const grpcObj = loadPackageDefinition(packageDef) as unknown as ProtoGrpcType;
this.grpcClient = new grpcObj.dataCalculatorPackage.DataCalculatorService(
`azurewebsite.url.com`,
credentials.createInsecure(),
);
However, when I run the request, I receive the following cancellation error:
[ERROR] 29 - 02/19/2024, 10:34:35 AM ERROR [ExceptionsHandler] 1 CANCELLED: Call cancelled 2024-02-19T10:34:35.863451309Z: [ERROR] Error: 1 CANCELLED: Call cancelled ...
I have also tried running the same images in my Docker, and it seems to work well. If anyone has any ideas, I would appreciate it.
Thanks!
The "CANCELLED" error you're encountering when deploying your gRPC server on Node.js to Azure Web App Service due to Server-Side Issues and Configuration Mismatches
The code below communicates with the server via gRPC, while also having an Express.js server handling HTTP requests.
I followed Configure gRPC on App Service - Azure App Service.
grpc_server.jsgrpc_client.jsWeb App Configuration:
Navigate to your web app's Configuration under Settings.
Click on the General Settings tab and scroll down to Platform settings.
Set the HTTP version to 2.0.
Enable the HTTP 2.0 Proxy.
Add an application setting named
HTTP20_ONLY_PORTwith the value8282.Update the
targetvariable inapp.jsto your web app's URL (e.g.,<your-app-name>.azurewebsites.net).Output: