Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

HTTPS required when server not on localhost #3

Closed
zer0yu opened this issue Aug 27, 2023 · 41 comments
Closed

HTTPS required when server not on localhost #3

zer0yu opened this issue Aug 27, 2023 · 41 comments
Labels
complete enhancement New feature or request

Comments

@zer0yu
Copy link

zer0yu commented Aug 27, 2023

I set it up by referring to your readme. However it does not open the synchronization process properly. I don't know if I need to apply https certificate? The specific error message is as follows:

image image
@acheong08
Copy link
Owner

Check your $HOST environment variable

@acheong08
Copy link
Owner

I might change the environment variable being read due to conflicts with pre-existing variables

@acheong08
Copy link
Owner

Also open up database.db and check what host the vault has stored.

@acheong08
Copy link
Owner

I don't know if I need to apply https certificate

The answer is most likely yes unless you're running it on localhost. They use https by default for the websocket

@zer0yu
Copy link
Author

zer0yu commented Aug 27, 2023

Ok, I'll configure the https. I have two more questions:

  1. Can I use IP directly for $HOST environment variable?
  2. Can you share the full Nignix config file?

@zxt-tzx
Copy link

zxt-tzx commented Aug 27, 2023

Trying to get this to work locally:

  • currently on a Mac (running both Obsidian + go run cmd/obsidian-sync/main.go)
  • I used export HOST=127.0.0.1
  • I updated the Obsidian Sync URL in the plugin to http://localhost:3000

The handlers are running and I can interact with them via cURL HTTP requests, but my Obsidian app on macOS doesn't seem to be working.

Happy to help with submitting PRs to get this working and developing this further (have been very annoyed by iCloud syncing not working well with Obsidian).

@ShiinaRinne

This comment was marked as resolved.

@ShiinaRinne ShiinaRinne mentioned this issue Aug 27, 2023
@acheong08
Copy link
Owner

Trying to get this to work locally:

* currently on a Mac (running both Obsidian + `go run cmd/obsidian-sync/main.go`)

* I used `export HOST=127.0.0.1`

* I updated the `Obsidian Sync URL` in the plugin to `http://localhost:3000`

The handlers are running and I can interact with them via cURL HTTP requests, but my Obsidian app on macOS doesn't seem to be working.

Happy to help with submitting PRs to get this working and developing this further (have been very annoyed by iCloud syncing not working well with Obsidian).

When running on localhost, there is no need to export HOST.

@acheong08
Copy link
Owner

To debug, you can open up the electron developer tools and do location.reload() to make sure all requests show up

@acheong08
Copy link
Owner

Can I use IP directly for $HOST environment variable?

Yes.

@acheong08
Copy link
Owner

By default, if you don't configure it:

var Host = "localhost:3000/ws"

@acheong08
Copy link
Owner

Can you share the full Nignix config file?

That is the full nginx config. My SSL/TLS is being handled by Cloudflare

@acheong08
Copy link
Owner

If you're running on localhost, there is no need for nginx ofc

@acheong08
Copy link
Owner

Another possible issue:

There has been a lot of breaking changes over the past few days & hours as I add new features. You might need to delete the db files and restart (and sign up again) if you've pulled new versions

@wangweitung
Copy link

It seems I suffer the same issue
below is my configuration and could you help me,thanks!
I have ubuntu server and a windows pc running obsidian.

1、 git clone https://github.com/acheong08/obsidian-sync
2、cd obsidian-sync
3、export HOST=192.168.1.204 - this is my ubuntu server ip
4、go run cmd/obsidian-sync/main.go
5、copy the code to nigx cofig file
image

6.set the plugin sync URL
image
7.create user and login
image

  1. I still get the error code 1006
    image
    image

  2. where did I do wrong ?please help

@acheong08
Copy link
Owner

acheong08 commented Aug 27, 2023

I don't see any connections to /ws or /.
Check where it's connecting via developer tools for the websocket

@acheong08
Copy link
Owner

Edit: Sorry. Light mode is killing me.

@wangweitung
Copy link

Edit: Sorry. Light mode is killing me.

sorry.... I did not use dark mode...

@acheong08
Copy link
Owner

image

What app is this?

@wangweitung
Copy link

image

What app is this?

opened from here

image

@acheong08
Copy link
Owner

acheong08 commented Aug 27, 2023

Ctrl + Shift + I to open devtools. It'll show what's going wrong. Then in console location.reload()

@wangweitung
Copy link

location.reload()

sorry for the light mode ...

image

@acheong08
Copy link
Owner

Ah here it is. It's using wss:// instead of ws://. It expects HTTPS when the endpoint is anything other than localhost or 127.0.0.1

@acheong08 acheong08 changed the title Unable to synchronize HTTPS required when server not on localhost Aug 27, 2023
@wangweitung
Copy link

Ah here it is. It's using wss:// instead of ws://. It expects HTTPS when the endpoint is anything other than localhost or 127.0.0.1

what should I do to make it work?

@acheong08
Copy link
Owner

what should I do to make it work?

Use something like certbot to get an TLS certificate.

@wangweitung
Copy link

what should I do to make it work?

Use something like certbot to get an TLS certificate.

I just use it in my inner network at home... could TLS be skipped?

@acheong08
Copy link
Owner

Here is the bit of code in the Obsidian app that manages this:

(t.prototype.getHost = function () {
              var e = this.host || "127.0.0.1:3003";
              return e.startsWith("127.0.0.1") || e.startsWith("localhost")
                ? "ws://" + e
                : "wss://" + e;
            }),

Another solution is to update the plugin to also intercept wss/ws requests but that'll take a while. (I have 0 experience in JS)

@acheong08
Copy link
Owner

could TLS be skipped?

It's hard coded into the app. For now, no

@wangweitung
Copy link

what should I do to make it work?

Use something like certbot to get an TLS certificate.

https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal&tab=standard

I'm trying by this instruction now...

@acheong08
Copy link
Owner

if (this.settings.SyncAPI.startsWith("http://")) {
	// Websocket intercept
	const originalWebSocket = window.WebSocket;

	// Override the WebSocket constructor
	window.WebSocket = class CustomWebSocket extends originalWebSocket {
		constructor(url: string, protocols?: string | string[]) {
			const newUrl = url.replace("wss://", "ws://");
			super(newUrl, protocols);
		}
	};
}

This might work in the plugin. Testing

@acheong08
Copy link
Owner

Issue: app.js loads before plugins. They make it a constant

@wangweitung
Copy link

Issue: app.js loads before plugins. They make it a constant

still thanks for ur effort...

@acheong08
Copy link
Owner

Note to whomever comes across this issue again: Cannot fix. HTTPS is required when not localhost

@acheong08 acheong08 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2023
@acheong08 acheong08 pinned this issue Aug 27, 2023
@acheong08 acheong08 added enhancement New feature or request help wanted Extra attention is needed upstream labels Aug 27, 2023
@zxt-tzx
Copy link

zxt-tzx commented Aug 28, 2023

Ctrl + Shift + I to open devtools. It'll show what's going wrong. Then in console location.reload()

Thank you so much for this. What I've done:

  • include console.log statements in the plugin to see when the plugin is loaded and unloaded
  • created an account and signed in on the About tab (this seems to be successful)

I see requests being made to the https://api.obsidian.md/user/info endpoints which are successfully intercepted by my local server, but I do not see any syncing attempts via the websocket connection.

Do I need to manually turn on Obsidian Sync from somewhere within the application's preference settings?

UPDATE: ah ok my bad, I need to turn on Sync within the Core Plugins page. will tinker further.

UPDATE 2: It's working now! What I did

  • Move my existing Vault out of iCloud
  • Go to Core plugins > Sync and connect to a new remote vault

Sorry if this is not the right thread, I could create a new issue here instead.

Thanks again!

@CzBiX
Copy link

CzBiX commented Aug 28, 2023

it's possible to use HTTP. you just have to hack the getHost of sync plugin.
solution here.

@acheong08
Copy link
Owner

@CzBiX Thank you! I don't actually know JavaScript, could you explain how you found this?

this.getInternalPluginInstance('sync').getHost = ()

I thought of the same but was unable to implement it because I couldn't find where the getHost function was

@acheong08
Copy link
Owner

I'm getting Property 'internalPlugins' does not exist on type 'App'.ts(2339)

@acheong08 acheong08 reopened this Aug 28, 2023
@CzBiX
Copy link

CzBiX commented Aug 28, 2023

@acheong08 It's not easy to explain, but in short, this is all that you can get with reverse engineering.

I'm getting Property 'internalPlugins' does not exist on type 'App'.ts(2339)

This is a non-public API that is not exposed, you have to use any in ts.

@acheong08
Copy link
Owner

// @ts-ignore: Property 'internalPlugins' does not exist on type 'App'.

This worked. Thank you!

@acheong08
Copy link
Owner

CC @wangweitung

You can update from https://github.com/acheong08/rev-obsidian-sync-plugin/releases/tag/1.0.3

Perhaps for the plugin, we can switch to using @CzBiX's repository considering they're much more experienced with JS

@acheong08 acheong08 added complete and removed help wanted Extra attention is needed upstream labels Aug 28, 2023
@wangweitung
Copy link

wangweitung commented Aug 28, 2023

CC @wangweitung

You can update from https://github.com/acheong08/rev-obsidian-sync-plugin/releases/tag/1.0.3

Perhaps for the plugin, we can switch to using @CzBiX's repository considering they're much more experienced with JS

thank you both , it's happy to hear this good news!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
complete enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants