uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.85k stars 570 forks source link

Wrap setYield #165

Closed ghost closed 4 years ago

dalisoft commented 4 years ago

I checked this method because i did think does like this, but not work like that.

The code i'm tested:

const { App } = require("uWebSockets.js");

const app = App();

app
  .any("/*", (res, req) => {
    console.log("req #1", req); // <-- this works like before
    req.foo = true;
    req.setYield(true);
  })
  .get("/get/*", (res, req) => {
    console.log("req #2", req); // <-- excepted req.foo = true
    req.bar = true;
    req.setYield(true);
  })
  .get("/get/user", (res, req) => {
    console.log("req #3", req); // <-- excepted req.foo = true and req.bar = true, but these does not exist
    res.end("done :)");
  });

app.listen(4000, token => token && console.log("listens at 4000"));

Try go to localhost:4000/get/user and see. May i missing something?

vimalmistry commented 3 years ago

@dalisoft Did you found any solution??

dalisoft commented 3 years ago

@vimalmistry I used workaround at high-level with simulating middlewares layer before every route request

vimalmistry commented 3 years ago

@dalisoft can you share sample code?

dalisoft commented 3 years ago

@vimalmistry Here snippet