jbyuki / instant.nvim

collaborative editing in Neovim using built-in capabilities
MIT License
1.26k stars 24 forks source link

Can't deploy a server using ngrok on Windows #16

Closed TheLeoP closed 11 months ago

TheLeoP commented 2 years ago

I just download this plugin today and the local editing works great. But I tried to follow the example of deploying a server using ngrok and it just don't works without giving me any errors.

I was trying to debug the code and I arrived at lua/instant/websocket_client.lua inside the method ws:connect, on the callback, on client:read_start it turns out that http_chunk does not match the expression "\r\n\r\n$" since the value is something similar to:

HTTP/1.1 307 Temporary Redirect\r\nContent-Type: text/html; charset=utf08\r\nLocation: https://6c33-186-34-245-88.ngrok.io:80/\r\nDate: Mon, 18 Apr 2022 20:58:46 GMT\r\nContent-Length: 75\r\n\r\n<a href="https://6c33-186-34-245-88.ngrok.io:80/">Temporary Redirect</a>.\n\n'

What confuses me the most is that using ngrok Web interface (https://localhost:4040) it doesn't even shows an http request being made but if I open the same URL on a web browser, it shows a Get request.

I thought this could be a firewall problem, so I turned it off and tryed again, but I got the same result.

Side note: what are the [something].lua.t files on src/ I found that you have a plugin to compile them to lua or (i think) vimscript, but what language/format are they? I tried to google it and just find something about Turing files.

sbmueller commented 2 years ago

I can't find the example for deploying a server at all. The link https://github.com/jbyuki/instant.nvim/wiki/Deploy-a-server doesn't seem to exist.

niveK77pur commented 2 years ago

I had a look at the commit history for the wiki page, and it seems the last commit there (as of today June 20, 2022) deleted the file for https://github.com/jbyuki/instant.nvim/wiki/Deploy-a-server. Hard to say if that was an accident or done on purpose because the info there is maybe outdated by now and does not work anymore.

$ git clone https://github.com/jbyuki/instant.nvim.wiki.git
$ cd instant.nvim.wiki/
$ git log --format=reference | head
b022417 (Destroyed Deploy a server (markdown), 2022-05-03)
03e96e2 (Updated Protocol (markdown), 2021-03-06)
ddc33d2 (Updated Protocol (markdown), 2021-03-06)
c232d47 (Updated Protocol (markdown), 2021-03-06)
96c3787 (Updated Commands (markdown), 2021-03-06)
adba71e (Updated Deploy a server (markdown), 2021-01-06)
d3707b7 (Updated Deploy a server (markdown), 2021-01-05)
b9fe3a0 (Updated Deploy a server (markdown), 2021-01-04)
c9d8bde (Updated Deploy a server (markdown), 2021-01-04)
1780f38 (Created Persistent Data (markdown), 2021-01-04)

At any rate, you can revert this deletion as follows. It will restore the Deploy-a-server.md which seems to contain the instructions.

$ git revert --no-edit b022417
[master dc95d66] Revert "Destroyed Deploy a server (markdown)"
 Date: Mon Jun 20 21:59:45 2022 +0200
 1 file changed, 90 insertions(+)
 create mode 100644 Deploy-a-server.md

I am on Linux, but the ngrok method does not seem to work either. Not sure if the issue is related to that of @TheLeoP, but in my case it does not seem to spit out any errors. It simply does nothing at all. Not even a GET / appears on ngrok (if I try to curl the link, a GET / appears).

Please note, I installed this plugin a few minutes ago, maybe I am missing something to get it to work.

If the deletion was intentional, I will be glad to delete this comment. In the meantime it can serve to retrieve the file.

rag-hav commented 2 years ago

@niveK77pur ngrok does work

PC 1

Vim

PC 2

Vim

niveK77pur commented 2 years ago

@rag-hav Thank you for your message! I see you are using TCP, does it also work for HTTP? (ngrok said I cannot use tcp until I create an account). So I am running ngrok http 8080 instead (PC 1).

Also just to clarify, when you say copy the url it is the one from Forwarding right? In my case it says something like https://1bf0-88-206-141-152.eu.ngrok.io -> http://localhost:8080 (note it says https, not sure if that's an issue. In the example they were showing it says http). So in the second PC I do :InstantJoinSingle 1bf0-88-206-141-152.eu.ngrok.io and it does nothing. :InstantStatus says Disconnected. (PC 2); on the first PC it says Connected. 0 other client(s)

The only other difference I see is that you are specifying a port on the second PC (you say 1821). Is it taken from the Web Interface entry? It says http://127.0.0.1:4040 for me, but adding 4040 or 8080 to the :InstantJoinSingle command also has no effect. (not sure if the port is specific to tcp in this case).


I just noticed, if I wait long enough after the join command, it eventually spits out this error message about a time out. In case that can help.

Error executing vim.schedule lua callback: ...im/plugged/instant.nvim/lua/instant/websocket_client.lua:92: There was an error during connection: ETIMEDOUT
stack traceback:
        [C]: in function 'error'
        ...im/plugged/instant.nvim/lua/instant/websocket_client.lua:92: in function 'cb'
        vim.lua:285: in function <vim.lua:285>

I glanced at the lua/instant/websocket_client.lua file at line 92 according to the above error. I see that this block of code is running inside a client:connect which leads me to line 68 where client is defined. It says

local client = vim.loop.new_tcp()

Does it mean it only works with TCP? I cannot use HTTP to make it work? In which case I might consider making an account to see if it actually works then. Or I might look into the second more complicated looking solution using Heroku if that can make any difference.

rag-hav commented 2 years ago

@niveK77pur

The only other difference I see is that you are specifying a port on the second PC (you say 1821). Is it taken from the Web Interface entry? It says http://127.0.0.1:4040 for me, but adding 4040 or 8080 to the :InstantJoinSingle command also has no effect. (not sure if the port is specific to tcp in this case).

With ngrok tcp you get a hostname and a port, which is different from Web Interface. But with HTTP you only get a hostname since the port for HTTP is always 80 by default.

For HTTP do this-

PC 1

Vim

PC 2

Vim

niveK77pur commented 2 years ago

Join :InstantJoinSingle foobar.ngrok.io 80 (for example)

Thank you again @rag-hav! This port 80 is something that must have slipped my attention. However, I just tried that and still no success :thinking:

I can ping the foobar.ngrok.io just fine though but running :InstantJoinSingle 1bf0-88-206-141-152.eu.ngrok.io 80 (for example) still reports Disconnected. I am getting unsure now where the issue exactly lies. It doesn't seem to be ngrok from what I gather here, but given what you tell me, it's probably not instant.nvim either... I'm not exactly sure where to look for now to trouble shoot this

rag-hav commented 2 years ago

@niveK77pur Well just on the off chance that you are making a mistake on some step. Here is a video

https://drive.google.com/file/d/1UJDoKDvJYCfCiTIFzaX3FcgcdvSAgO00/view?usp=sharing

niveK77pur commented 2 years ago

Thank you so much again @rag-hav! I have spotted the culprit thanks to your video. There are 2 things that differ on both our ends.

  1. Your version of ngrok is 2.3.40. Mine is 3.0.5. But I believe this not to be an issue.
  2. You have two Forwarding entries. One with http, and another with https. I only see a single entry with https.

I see the URL is otherwise the same, so I suppose the issue is that I am not receiving an http tunnel (which seems to be part of the free subscription).

I have just gone ahead and created an ngrok account because it does seem quite cool. And I got it to work with TCP now!


However, I still don't see the http forwarding for ngrok, only https. I suppose there is an issue with my ngrok? or I need to configure something? or is it because I am in the EU? This is not related to this plugin anymore though.

Also keep in mind, I did not open this issue. So I am not sure if my discoveries here could help resolve the initial problem raised.