1

I am building a SPA with Angular 4. As API-Backend I am using Node.js with Express.js Framework. I also configured WebSockets on my Backend-Server, so the same API-Server can establish WebSocket-connections.

My current Problem: When I am doing "not simple HTTP-request", as it described at mozilla CORS-page (I am using Authorisation Header with JWT Bearer), browser makes before every request an OPTIONS HTTP-request... I understand, that there is no way in my case to change this behaviour, but I got an idea...

Idea: As mentioned above, I use WebSockets in my SPA, that are already connected with my API-backend. Is it a good idea, to make all the communication through WebSockets? I maybe get a problem, that I have to implement listeners on both sides for one action (request-listener in API-Server and response-listener in SPA), but this way Browser don't have to do all these annoying OPTIONS-requests, that also take some time to execute (SPA should word well with 3G connection)

What do you think? Is it a good idea? Or is it horrible? Are OPTIONS-Requests so light and fast, so i don't have to worry about the additional latency that much?

Thank you for every advice and opinion!

lorado
  • 336
  • 1
  • 7
  • http2.0 to be sure that you are in single connection, or... back to the 2000 - jsonp – zb' Jul 16 '17 at 17:34
  • also I see no problem to just estabilish one websocket and incapsulate to it any number of flows you need to make your spa work as you wish. use something like socket.io to make duplex socket messaging system. – zb' Jul 16 '17 at 17:36
  • https://stackoverflow.com/questions/15568700/best-java-server-implementation-for-socket-io – zb' Jul 16 '17 at 17:40

0 Answers0