3

I'm running a coap server, and as I've started adding routes, maintaining my own routing is a bit tedious so I thought I'd switch to express (which I already use for an http server).

Now, given that it uses basically the same format for server.on("request", (req, res) => {...}), I assumed it would be compatible, but express adds various headers that aren't in the coap spec.

What I want to be able to do is just use the convenience of express routing for my coap app. Is this possible? I'm currently doing this:

const server = coap.createServer(...);
const app = express();
server.on("request", app);

What I end up with is this error:

 Uncaught Error: Unknown string to Buffer converter for option: X-Content-Type-Options
  at module.exports.toBinary (node_modules/coap/lib/option_converter.js:21:11)
  at OutMessage.setOption (node_modules/coap/lib/helpers.js:56:16)
  at Immediate.write (node_modules/finalhandler/index.js:164:9)
GTF
  • 8,031
  • 5
  • 36
  • 59

1 Answers1

0

I made a little debug and the problem probably is something about the request header, that sends to coap library unexpected fields and it doesn's make sense for coap protocol/lib.

For example, in node_module/finalhandler/index.js, I commented from line 163 to 168 and got new errors about route handler.

I have the same issue since I need to build a coap server too, but I think is easier to build the routes without express or build another express-like framework to coap. Also, something like express-load for coap would be a good help as it helps on commom express projects.