Streaming data between frontend and backend appliction

470 views
Skip to first unread message

Ryan Mahoney

unread,
Nov 11, 2015, 4:04:49 PM11/11/15
to openresty-en
Hi everyone,

I have a backend written in Python and a Frontend written in Javascript.

What I'd like to do is setup a configuration such that when a request comes through, it is first sent to the backend, then the response from the backend is sent to the frontend.

The backend application is a web server, the front-end application listens for input on unix domain socket.

My question is: is it possible to take the output stream from the backend server response, and send that as stdin to the frontend application and then send that response back to the client?

I've used Nginx for many years, but I am new to open resty.

In a real world use case, I would detect GET requests that were sent via XHR and only send them to the backend.  If it were a GET request not sent via XHR, I would want to do this "piping" approach of sending the output from the backend app to the frondend app before sending a fully rendered page down to the client.

I think this approach has some interesting benefits, as it would a allow for server-side rendering of pages that use Javascript technology (such as React JS) without the backend application needing to know in any way what sort of frontend application it may be working with.

Currently, many people are using Python, Ruby, PHP etc to send their backend response to a Javascript rendering script, but this is a condition in the backend code where the backend will open this connection, and it will send the response back.  While this may not seem overly problematic, it makes the backend and frontend coupled together.  I'd like to have the flexibility to have many frontend applications that can render pages on the server side without the backend having any knowledge of who or what application is consuming the data.

Eagerly awaiting your thoughts on this.

Best,
Ryan

Lord Nynex

unread,
Nov 11, 2015, 6:31:31 PM11/11/15
to openre...@googlegroups.com
Your use case is a bit confusing. If I understand properly, there is a frontend app (python) and a backend app (python) and you want to direct the client to one or the other depending on some request header? 



--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Mahoney

unread,
Nov 12, 2015, 10:05:57 AM11/12/15
to openresty-en
Sorry, I was too long winded.

The essential aspect I'm looking into it whether I can:
  1. send the initial http request to a backend
  2. send the response of the first backend as input to a second backend
  3. send the output of the backend to the client
I think think this may be fairly easy to to with Lua in Nginx (but I'm new to openresty).

I was hoping to a send the output from the first backend as stdin to the second backend though a unix domain socket.

It's also true that depending on a header, I will choose to send the response from the first backend without passing it through the second backend, but that is something that Nginx can do out-of-the-box without Lua, etc.

Thanks for any guidance!

Best,
Ryan
Reply all
Reply to author
Forward
0 new messages