braid-org / braidjs

Monorepo for Braid Projects in Javascript
https://braid.org
262 stars 15 forks source link

Not able to run the demo #24

Closed thhck closed 1 month ago

thhck commented 5 months ago

Hello,

I was not able to run the demo from braid-http/demos/chat is it up to date ? I had to edit server.js +19 to var braidify = require('../blog3/braidify-server') and even after that I got: GET https://localhost:3009/chat net::ERR_CONNECTION_REFUSED errors in the console when browsing https://localhost:3009/

toomim commented 5 months ago

Oh, interesting! Checking it out ...

toomim commented 5 months ago

Some of this code is definitely out-of-date. I'm updating it now.

toomim commented 5 months ago

This code is very out-of-date. I'm working on fixing it, but in the meantime, I'd work from the examples at https://www.npmjs.com/package/braid-http and the test server inside the test/ folder.

thhck commented 5 months ago

from examples at https://www.npmjs.com/package/braid-http

Do you mean the example in the readme ?

Because I was not able to make them work, but maybe it because of a lack of understanding of braid. I could give it another try after digging more into braid's documentation.

and the test server inside the test/ folder.

I was able to make it run, but http://localhost:9000 give me mostly red screen , but ( like 1 out of 8 time ) sometime a green screen. Is this expected behavior ?

toomim commented 5 months ago

Yes, I did mean the examples in the readme.

I am surprised that they, and the test/ server, are not working for you. Let's try to debug this 1-1! I'll send you an email.

toomim commented 5 months ago

I've updated the demo, and renamed it to demos/blog instead of blog3. It's functioning for me now.

toomim commented 5 months ago

It looks like this is why the demo was failing: https://github.com/spdy-http2/node-spdy/issues/380

The spdy library stopped working on node v15. I switched the demo to use http2-express-bridge instead.

toomim commented 5 months ago

I was able to make it run, but http://localhost:9000 give me mostly red screen

Can you copy and paste the section under "Our Results" into here from one of the red runs? (Note that I just renamed it to "Your Server's Responses" in master to be clearer.)

thhck commented 5 months ago

Without the latest change, that was the result I was having:

Failed! :(
Our Results

Read 1 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Read 1 {"version":["test1"],"parents":["oldie","goodie"],"patches":[{"unit":"json","range":"[1]","content":"1"}],"extra_headers":{"hash":"42"}}!
Read 1 {"version":["test2"],"patches":[{"unit":"json","range":"[2]","content":"2"}]}!
Read 1 {"version":["test3"],"patches":[{"unit":"json","range":"[3]","content":"3","extra_headers":{"hash":"43"}},{"unit":"json","range":"[4]","content":"4"}]}!
Read 3 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Read 2 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Read 2 {"version":["test1"],"parents":["oldie","goodie"],"patches":[{"unit":"json","range":"[1]","content":"1"}],"extra_headers":{"hash":"42"}}!
Read 2 {"version":["test2"],"patches":[{"unit":"json","range":"[2]","content":"2"}]}!
Read 2 {"version":["test3"],"patches":[{"unit":"json","range":"[3]","content":"3","extra_headers":{"hash":"43"}},{"unit":"json","range":"[4]","content":"4"}]}!
Write test 1 returned 200
Write test 2 returned 200
Write test 3 returned 200
Write test 4 returned 200
Read 3 {"version":["another!"],"body":"\"!\""}!
Read 1 {"version":["another!"],"body":"\"!\""}!
Read 2 {"version":["another!"],"body":"\"!\""}!

Known Results

Read 1 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Read 1 {"version":["test1"],"parents":["oldie","goodie"],"patches":[{"unit":"json","range":"[1]","content":"1"}],"extra_headers":{"hash":"42"}}!
Read 1 {"version":["test2"],"patches":[{"unit":"json","range":"[2]","content":"2"}]}!
Read 1 {"version":["test3"],"patches":[{"unit":"json","range":"[3]","content":"3","extra_headers":{"hash":"43"}},{"unit":"json","range":"[4]","content":"4"}]}!
Read 2 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Read 2 {"version":["test1"],"parents":["oldie","goodie"],"patches":[{"unit":"json","range":"[1]","content":"1"}],"extra_headers":{"hash":"42"}}!
Read 2 {"version":["test2"],"patches":[{"unit":"json","range":"[2]","content":"2"}]}!
Read 2 {"version":["test3"],"patches":[{"unit":"json","range":"[3]","content":"3","extra_headers":{"hash":"43"}},{"unit":"json","range":"[4]","content":"4"}]}!
Read 3 {"version":["test"],"parents":["oldie"],"body":"{\"this\":\"stuff\"}"}!
Write test 1 returned 200
Write test 2 returned 200
Write test 3 returned 200
Write test 4 returned 200
Read 1 {"version":["another!"],"body":"\"!\""}!
Read 2 {"version":["another!"],"body":"\"!\""}!
Read 3 {"version":["another!"],"body":"\"!\""}!

From firefox

However, use google's chromium I had 100% green pages

toomim commented 5 months ago

Ohhh... I haven't tested Firefox for a bit! I'll get on that.

It looks like the only difference is the ordering of the events:

image

So no worries— it's working! Firefox is known to do some buffering on the streams returned from fetch(). We actually detect firefox in the braid-http server and send it extra blank lines after updates in order to force it to flush its cache and return the event to the client. It's possible that this buffering is causing some of the reads to be delayed, which might make them arrive out-of-order. I'll look into it so that we don't get scary test failure messages. :-P

Thanks for providing this test-case!

thhck commented 5 months ago

Was able to run the blog demo on braid-http/demos/blog :+1:
However I'm still having a bug with the chat demo.

In server.js , seems that the file doesn't exist line 16: var braidify = require('../../braidify-server')

Should this be var braidify = require('../../braid-http-server.js') instead ?

toomim commented 5 months ago

Ah, yes I haven't updated the chat demo — that looks right!

There might be other changes necessary to get it up to speed too... digging in...

toomim commented 5 months ago

BTW, these demos are poorly named — the difference is that the "blog" fetches an index of posts, and then each individual post separately, whereas the "chat" fetches an array of all the post data.

You might also check out the braidmail repo, which is an elaboration of the "blog" approach:

toomim commented 5 months ago

I've fixed the chat demo. I'm sorry for allowing broken code to lay around. Thank you for bringing it to our attention!