colyseus / uWebSockets-express

Express API compatibility layer for uWebSockets.js
https://npmjs.com/package/uwebsockets-express
MIT License
56 stars 13 forks source link

Full body not received #24

Closed girishghoda closed 1 year ago

girishghoda commented 1 year ago

Here is the code which we have implemented

try {
    var uWebSockets_js_1 = require('uWebSockets.js');
    var uwebsockets_express_1 = require("uwebsockets-express");
    var uwsApp = uWebSockets_js_1.App();

    var app = (uwebsockets_express_1.default)(uwsApp);
    const server = http.createServer((req, res)=>{
      app(req, res)
    });

    app.listen(port, function (err) {
      app.post("/data", function (req, res) {
        console.log('body', req.body)
        res.json({ hello: "world!" });
      });
    });
  } catch (er) {
    console.log('er', er);
  }

Issue

Sometimes the full body is not received as req.body

Findings

Received body (which cause SyntaxError: Unexpected token , in JSON at position 2 due to body is not fully received)

body ","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":310,"y":220,"wires":[["d69ad624.954638"]]},{"id":"d69ad624.954638","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":500,"y":220,"wires":[]},{"id":"91d9c572.8a1bb8","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":110,"y":340,"wires":[["9739a876.c5deb8"]]},{"id":"9739a876.c5deb8","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":310,"y":340,"wires":[["e676b9c1.473868"]]},{"id":"e676b9c1.473868","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":500,"y":340,"wires":[]},{"id":"a2894126.7ee02","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":110,"y":400,"wires":[["802fcac3.58f838"]]},{"id":"802fcac3.58f838","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":310,"y":400,"wires":[["6bef2693.2788d8"]]},{"id":"6bef2693.2788d8","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":500,"y":400,"wires":[]},{"id":"b643fc2.3de89","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":110,"y":460,"wires":[["b36eb1a8.17c2b"]]},{"id":"b36eb1a8.17c2b","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":310,"y":460,"wires":[["f84a970.0d71968"]]},{"id":"f84a970.0d71968","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":500,"y":460,"wires":[]},{"id":"7e1f5f86.6c131","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":670,"y":40,"wires":[["8aa649f6.f06948"]]},{"id":"8aa649f6.f06948","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":870,"y":40,"wires":[["a645f8a6.52e358"]]},{"id":"a645f8a6.52e358","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":1060,"y":40,"wires":[]},{"id":"e80a8989.ea5278","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":670,"y":100,"wires":[["eb78714a.82d68"]]},{"id":"eb78714a.82d68","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":870,"y":100,"wires":[["48f1ae97.bdbdf"]]},{"id":"48f1ae97.bdbdf","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":1060,"y":100,"wires":[]},{"id":"6b3b8991.f8d3a8","type":"http in","z":"f1f6b604.8b97b","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":670,"y":160,"wires":[["d617e9eb.e5a638"]]},{"id":"d617e9eb.e5a638","type":"function","z":"f1f6b604.8b97b","name":"","func":"var require = context.global.get('require'); \n\nmsg.payload = {\"status\":\"success\"};\n\nreturn msg;","outputs":1,"timeout":10000,"newThread":false,"noerr":0,"x":870,"y":160,"wires":[["23ec6d3e.5cbb52"]]},{"id":"23ec6d3e.5cbb52","type":"http response","z":"f1f6b604.8b97b","name":"","statusCode":"","headers":{},"x":1060,"y":160,"wires":[]}],"rev":"dd558e227813e71e4b213ee372a51251"}

@endel

endel commented 1 year ago

Awesome, thanks @girishghoda!

girishghoda commented 1 year ago

Fixed in #26