-
Notifications
You must be signed in to change notification settings - Fork 438
[FIX] Enable support for Rocket hosted on subdirectory #1277
[FIX] Enable support for Rocket hosted on subdirectory #1277
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jpowie01 !!
Let's see how we can fix this problem in the best way possible.
- What server are you using to test this? Is it public?
- I requested couple changes for now.
@@ -40,15 +40,15 @@ class API: APIFetcher { | |||
var userId: String? | |||
|
|||
convenience init?(host: String, version: Version = .zero) { | |||
guard let url = URL(string: host) else { | |||
guard let url = URL(string: host)?.httpServerURL() else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't make these changes here.
It would be better if we make this change where we are initializing the API object.
Take a look at APIExtensions.swift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Rocket.Chat/API/API.swift
Outdated
return nil | ||
} | ||
|
||
self.init(host: url, version: version) | ||
} | ||
|
||
init(host: URL, version: Version = .zero) { | ||
self.host = host | ||
self.host = host.httpServerURL() ?? host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Yes, my server is publicly available but I wouldn't like to share a link here. I can send you an URL to my instance via email if you want to test it on your own. I'll try to resolve above comments today. Thanks! :) |
@jpowie01 Great! You can send me the link at https://open.rocket.chat/direct/matheus.cardoso |
|
||
XCTAssertEqual(object.apiHost?.absoluteString, "https://team.rocket.chat/subdirectory/", "apiHost returns API Host correctly") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
XCTAssertEqual(object.apiHost?.absoluteString, "https://team.rocket.chat/subdirectory/", "apiHost returns API Host correctly") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
|
||
XCTAssertEqual(object.apiHost?.absoluteString, "https://team.rocket.chat/subdirectory/", "apiHost returns API Host correctly") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
…ocket.Chat.iOS into rocket_hosted_on_subdirectory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my tests, the custom emojis of open.rocket.chat
didn't load. Can you guys also reproduce the issue?
You're right! Debugged, fixed & pushed to this PR :) |
…ocket.Chat.iOS into rocket_hosted_on_subdirectory
…rocket_hosted_on_subdirectory
@jpowie01 Tests aren't passing... can you take a look again please? I tried re-run the CI but still didn't pass. |
Could you help me guys with reproduction? All tests passes on my local machine. Here are logs from above test taken from Xcode:
Am I right that I'm lucky it ends just before the deadline (1.1 second)? I rerun tests a couple of times and it just works:
My setup: Xcode Version 9.0.1 (9A1004). |
@cardoso The test is failing in a "wait()" method. Can you take a look please? |
It's most likely a random crash @rafaelks. I'll take a look. |
@jpowie01 Just made some testing and looks like the loading of attachments doesn't work on servers with subdirectory. Steps to reproduce:
Can you fix this one also, please? |
Thanks for that! I'll look into this issue tomorrow. That's probably a problem with string concatenation instead of API usage for building URLs. |
@jpowie01 Sure! Let me know when you're done, we're looking to merge this one for next release. 👍 |
I've debugged it and... it's strange :/ iOS application points to this place if it would like to fetch an attachment (eg. an image): But... the file is actually available under this path: So... Sending attatchments in browser works because it points to a place with double subdirectory in path! What's more - desktop (Mac) application points to a single subdirectory path (like an iOS app) which causes the same issues as described here. Maybe my server settings are broken? But it would be strange as all other things seems to work like a charm. For me, it sounds like a bug on the server side... Do you have any other instance running on a subdirectory just for testing? |
@jpowie01 Thanks for looking into it. Looks like there's a bug on upload. I'll try to investigate with the back-end guys to see what's going on. |
@jpowie01 Yes, the issue is fixed already and will be released to next release: RocketChat/Rocket.Chat#10029. I'll try your PR with this version of the server and I'm gonna merge it if that works fine. Thank you!!! |
Cool, great! Thanks for confirmation! :) |
I've updated my server to use the latest version of Rocket.chat and it fixed issues with attachments :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!!! Thank you!
@@ -58,7 +58,7 @@ extension APIRequest { | |||
|
|||
func request(for api: API, options: APIRequestOptions = .none) -> URLRequest? { | |||
var components = URLComponents(url: api.host, resolvingAgainstBaseURL: false) | |||
components?.path = path | |||
components?.path += path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RocketChat/ios Guys, this +=
has introduced a bug, because we specify our paths as the following: /api/v1/me
, and if we concatenate this path with the default path of an URLComponents
it will result in a duplicated initial slash as the following: //api/v1/me
which makes the request invalid.
It took me a while to discover what was going on because the result it is generating is not even handled as an error by the app, so it generated confusing behaviors such as making the app stuck on an endless loading in the auth screen, or even authenticating the user with a nil
user 🕵️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1415 fixes it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filipealva Thank you! 👍
@RocketChat/ios
Closes #900
These changes make sure that API Requests will follow HTTP protocol with applied subdirectory on which Rocket.Chat Server is hosted. Also, saves HTTP connection to the database instead of WebSocket one.
Note: It would be nice if anyone would like to check it out and even countinue work on this as I'm not familiar with Swift/iOS/Rocket.Chat.iOS at all. It's my proposal for changes :)