CoderSerio commented on issue #387:
URL: https://github.com/apache/dubbo-js/issues/387#issuecomment-2017889104

   
   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:
   
   1. Handle the preflight OPTIONS request, which must be separately addressed 
by calling res.end.
   2. Handle the real request with the API `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:
   ```ts
   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") {
       // 处理预检请求(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";);
   });
   ```
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to