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

Sending custom headers #30

Open
gciluffo opened this issue May 7, 2018 · 0 comments
Open

Sending custom headers #30

gciluffo opened this issue May 7, 2018 · 0 comments

Comments

@gciluffo
Copy link

gciluffo commented May 7, 2018

I see there are multiple PR's for adding custom request headers. However, whenever I try sending up custom headers with this library in angular I cant seem to get any message to the client when I do client.send("Testing!"). Even though it is making the connection.

However it seems to work just fine when I dont send up any headers. Has anyone run into this issue before?

Client:

this.eventSource = new EventSourcePolyfill('http://localhost:3000/sse', 
    { headers: 
      { 'Authorization': `Bearer ${localStorage.getItem('token')}`, 
        'ocp-apim-subscription-key': environment.worklistApiSubKey }
    });

Server:

export function initializeSSE(server: Server) {
  sse = new SSE(server);
  sse.on('connection', (client: any) => {
    log.info(`new clint connected ${client.req.url}`);
    client.send({data: 'Sup Kyle!'});
  });
}

Ive also added supporting for custom header on the initialization

SSEClient.prototype.initialize = function() {
  this.req.socket.setNoDelay(true);
  this.res.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache, no-transform',
    'Connection': 'keep-alive',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'Authorization, ocp-apim-subscription-key'
  });
  this.res.write(':ok\n\n');
};
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