Closed CoderSerio closed 8 months ago
Well, now I’ve resolved it🥳. This issue occurs because there is a conflict resulting from res.end
and dubboNodeAdapter
, which both attempting to send response for the same request. When dealing with Dubbo RPC requests within a raw NodeJS server environment, there are two stages to manage:
res.end
.dubboNodeAdapter
instead of res.end
—either using its built-in handling logic or by manually executing the handler provided by it, as appropriate for the situation at hand.The modified code now looks as follows:
import { createServer } from "http";
import { dubboNodeAdapter } from "@apachedubbo/dubbo-node";
import dubboRoutes from "./router";
const server = createServer((req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "*");
res.setHeader("Tri-Service-Group", "dubbo");
res.setHeader("Tri-Service-Version", "1.0.0");
if (req.method === "OPTIONS") {
// handle the preflight request(OPTIONS)
res.end();
return;
}
console.log("get a request!");
const handler = dubboNodeAdapter({
routes: dubboRoutes,
fallback: (...args) => {
console.log("fallback", args);
},
});
handler(req, res);
});
server.listen(8000, () => {
console.log("\ndubbo-js server is running on http://localhost:8000...\n");
});
Relevant Code
The relevant code is as follows
package apache.dubbo.demo.helloworld;
message SayRequest { string sentence = 1; }
message SayResponse { string sentence = 1; }
service MyService { rpc Say(SayRequest) returns (SayResponse) {} }
const server = createServer((req, res) => { console.log("get a request!", req); // key code is here dubboNodeAdapter({ routes: dubboRoutes }); res.end("Response"); });
server.listen(8000, () => { console.log("\ndubbo-js server is running on http://localhost:8000...\n"); });
Steps to reproduce
Bug