cancel
Showing results for 
Search instead for 
Did you mean: 

Using SAP approuter with server-sent events

manuel_seeger
Explorer
0 Kudos
551

Dear colleagues, 

Has anyone managed to make SAP approuter work with server-sent events? 

https://www.npmjs.com/package/@sap/approuter

We are using approuter as the entry point for applications on BTP. Right now we are building a chat application which uses server-sent events for real time communication between client and server: 

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events

However, it looks like approuter does not support this. Requests send to the backend destination with Accept: text/event-stream stay open, but no data/event is received back from the backend on those requests. 

The application works fine without approuter in front of it. It looks like approuter blocks those events, or possibly is waiting for the initiating request to finish before sending anything back to the client (which would render server-sent events useless). 

Now I have not found any documentation that says event streaming is not supported by approuter. Has anyone made it work? Is there a setting or combination of settings in approuter or the destination server that is required for server-sent events to work? 

Best regards,

Manuel

View Entire Topic
manuel_seeger
Explorer

To anyone else finding this, I finally made it work. 

The problem is compression middleware used in approuter.

https://www.npmjs.com/package/@sap/approuter#compression-property

Since the SSE request doesn't have a content-length and does not complete, I suspect approuter is unable to decide whether to apply compression or not, and the requests hangs. If the connection is cleanly closed, all messages are being sent at once. 

To make it work, disable compression on your SSE requests. Ideally, your server sets the Cache: no-transform header directive. 

Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Cache: no-transform header did not work for me. However, when i disabled compression completely, it worked!

0 Kudos
Hi, that's a great finding.Which kind of your approuter is, a standardlone or managed one? I got the same problem when I deployed my app to SAP Workzone, And I set the compression property in the xs-app.json on app level not works.However if I use a standardlone approuter it works.