Sigh... I forgot to reply to the list... Here we go:

I want a single HTTP server like serve/servlet (or similar) that handles
all requests by the standard dispatcher/c logic - ideally using
dispatch/servlet with dispatch-case to specify the mapping. And for one
specific URL path "/sockjs-node", I need it to be able to do the
websocket HTTP 101 protocol switch.

The React.js application in the browser just communicates using HTTP and
if you run its minimal node.js server with "npm start" its HTTP
implementation contains the selective websocket URL path and it works. I
just need a way to proxy this, as my Racket backend is the HTTP server.
For static data I produce response/full with that data, for API calls,
it is response/jsexpr and for this websocket endpoint, I would like to
run copy-port and be done with it - after the protocol switch, that is.

>From what I read about rfc6455 package, it cannot be used with the
web-server package. I'll dive into the source later today.

Actually I can live without that, yet I was curious as it provides a
convenient way to reload the frontend after source changes in its code
(that is the Javascript part). For production builds, a plain
serve/servlet does all the job required.


Dominik

On 11. 01. 20 3:18, Jay McCarthy wrote:
> I don't completely understand what you want to do. Is there a reason
> you can't use the WebSocket implementation ---
> https://docs.racket-lang.org/rfc6455/index.html --- and then use
> normal inter-Racket communication like channels and stuff to work with
> the rest of your Web application?
> 
> Jay
> 
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
> 
> On Thu, Jan 9, 2020 at 5:23 PM Dominik Pantůček
> <dominik.pantu...@trustica.cz> wrote:
>>
>> Hello everyone,
>>
>> I am working on an application that uses React.js[1] for front-end and
>> Racket as HTTP back-end server.
>>
>> For production builds, the Javascript part is compiled using "npm build"
>> which generates a directory full of HTML and Javascript files which are
>> then included in the Racket application during syntax stage as an
>> immutable hash. For development builds, the Racket application runs "npm
>> start" in the front-end source directory and proxies all non-backend
>> requests to the managed node.js server.
>>
>> When run in the development setup (that is with the node.js secondary
>> HTTP server), the proxying using serve/servlet and simple dispatch-case
>> works like a charm - each servlet uses http-sendrecv to get the data
>> from the secondary HTTP server and returns it as appropriate response body.
>>
>> But the reason for this setup is that React.js can automatically reload
>> the webpage, if any of the source files change. To do this trick, it
>> uses an url "/sockjs-node". The browser sends GET request for this
>> resource and the node.js server responds with "HTTP/1.1 101 Switching
>> Protocols" like in [2].
>>
>> Apparently, to make this work, I need to establish a bi-directional
>> connection after the 101 response code. This is impossible with
>> serve/servlet. I have done some experiments with plain (serve #:dispatch
>> ...) and just cannot make it work all at once. With connection-i-port
>> and connection-o-port it should be (relatively) easy to implement. But
>> the documentation is virtually nonexistent and browsing the
>> web-server/private/ sources is a bit tricky if I do not know what I am
>> looking for.
>>
>> If anyone can give me a hint how a proper setup for websocket
>> implementation should look like, I would really appreciate it. Of
>> course, I also want to use the dispatch-case with plain requests as it
>> automates most of the real work I need to perform there.
>>
>>
>>
>> Cheers,
>> Dominik
>>
>> [1] https://reactjs.org/
>> [2] https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/a3834699-4ed6-f337-1409-9f175636c087%40trustica.cz.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/8222caa5-0104-a0b4-2e08-53ec731ac2bb%40trustica.cz.

Reply via email to