Skip to content

Commit

Permalink
Update local server to handle triple slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Jan 29, 2024
1 parent 83d9de0 commit 42a0b9d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions apps/menu-bar/macos/ExpoMenuBar-macOS/SwifterWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,30 @@ private let WHITELISTED_DOMAINS = ["expo.dev", "expo.test", "exp.host"]
}

private func extractRootDomain(from urlString: String) -> String {
guard let originUrl = URL(string: urlString.removingPercentEncoding ?? ""),
var hostName = originUrl.host else {
guard let originUrl = URL(string: urlString.removingPercentEncoding ?? "") else {
return ""
}

// Orbit deeplink may include specific routes in the URL e.g. /update, /snack, /download, etc.
if !hostName.contains(".") {
var hostName: String
if let originalHostName = originUrl.host {
hostName = originalHostName
} else {
// Orbit deeplink may include specific routes in the URL e.g. /update, /snack, /download, etc.
let components = NSURLComponents(url: originUrl, resolvingAgainstBaseURL: true)
let urlStringFromParams = components?.queryItems?.first(where: { $0.name == "url" })?.value

if urlStringFromParams != nil {
let urlFromParams = URL(string: urlStringFromParams ?? "")
hostName = urlFromParams?.host ?? ""
} else {
hostName = originUrl.pathComponents[1]
hostName = ""
}
}

if !hostName.contains(".") {
hostName = originUrl.pathComponents[1]
}

let components = hostName.components(separatedBy: ".")
if components.count > 2 {
return components.suffix(2).joined(separator: ".")
Expand Down

0 comments on commit 42a0b9d

Please sign in to comment.