Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http server & httpHandlers Object Question #20

Open
poppabear8883 opened this issue Apr 10, 2019 · 0 comments
Open

http server & httpHandlers Object Question #20

poppabear8883 opened this issue Apr 10, 2019 · 0 comments

Comments

@poppabear8883
Copy link

First, please forgive me as I am fairly new to the subject and am still learning about upnp and ssdp.

With that said, I am trying to "tap" into the http server request system so that I can handle additional requests however my method seems to give me

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

I suspect because of the way your http server is implemented. It looks like you define httpHandlers to handle requests, but obviously it does not appear that I can tap into that from the peer.

I will provide to you what I have that is giving me the above error in case its simpler then what I am seeing:

function onRequest(req, res) {

  switch (req.url) {
    case '/discover.json':
      if (req.method === 'GET') res.end(JSON.stringify(getDiscoverJson()));
      break;
    case '/lineup.json':
      if (req.method === 'GET') res.end(JSON.stringify(getLineupJson()));
      break;
    default:
      if (req.method === 'GET') res.end(JSON.stringify(getDiscoverJson()));
  }

}

const httpServer = http.createServer(onRequest).listen(PORT);
console.log(`Listening on ${PORT}`);

// ... methods that return an object for the json responses

// peer
const peer = upnp.createPeer({
  prefix: "/upnp",
  server: httpServer
}).on("ready", async (peer) => {
  console.log("Device Ready");
  device.advertise();
}).on("close", (peer) => {
  console.log("closed");
}).start();

const device = peer.createDevice({
  // all my options
});

Please advise A.S.A.P

Much appreciated in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant