HugoRodriguesQW / rsa-bridge

Encrypted communication bridge using RSA keys between frontend and backend
https://rsa-bridge.vercel.app
MIT License
1 stars 0 forks source link

RSAServer.publish not working as express handler #2

Open HugoRodriguesQW opened 5 months ago

HugoRodriguesQW commented 5 months ago

Run:

rsa = new RSAServer({bits: 1024})
app.get("/publickey", rsa.publish)

Error:

TypeError: Cannot read properties of undefined (reading 'publicKey') at publish (/home/username/project/node_modules/rsa-bridge/dist/modules/server.js:20:23) at Layer.handle [as handle_request] (/home/username/project/node_modules/express/lib/router/layer.js:95:5) at next (/home/username/project/node_modules/express/lib/router/route.js:149:13) at Route.dispatch (/home/username/project/node_modules/express/lib/router/route.js:119:3) at Layer.handle [as handle_request] (/home/username/project/node_modules/express/lib/router/layer.js:95:5) at /home/username/project/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/home/username/project/node_modules/express/lib/router/index.js:346:12) at next (/home/username/project/node_modules/express/lib/router/index.js:280:10) at expressInit (/home/username/project/node_modules/express/lib/middleware/init.js:40:5) at Layer.handle [as handle_request] (/home/username/project/node_modules/express/lib/router/layer.js:95:5)

Publish function:

 /** Returns an http handler responsible for exposing the public key of the RSA service */
  publish(_: any, res: any) {
    if (typeof res?.contentType === "function") res.contentType("text");
    if (typeof res?.status === "function") res.status(200);

    return res?.json({
      key: this.publicKey("public"),
      format: "public",
    });
  }
HugoRodriguesQW commented 5 months ago

Temporarily it can be worked around using:

app.get("/publickey", (_, res) => {
  rsa.publish(_, res);
});