This repository was archived by the owner on Jul 19, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -104,22 +104,45 @@ toRoute =
104
104
oneOf [ b perspective, b definition ]
105
105
106
106
107
+ {- | In environments like Unison Local, the UI is served with a base path
108
+
109
+ This means that a route to a definition might look like:
110
+
111
+ - "/:some-token/ui/latest/terms/base/List/map"
112
+ (where "/:some-token/ui/" is the base path.)
113
+
114
+ The base path is determined outside of the Elm app using the <base> tag in the
115
+ <head> section of the document. The Browser uses this tag to prefix all links.
116
+
117
+ The base path must end in a slash for links to work correctly, but our parser
118
+ expects a path to starts with a slash. When parsing the URL we thus pre-process
119
+ the path to strip the base path and ensure a slash prefix before we parse.
120
+
121
+ -}
107
122
fromUrl : String -> Url -> Route
108
123
fromUrl basePath url =
109
124
let
110
- stripBasePath u =
125
+ stripBasePath path =
111
126
if basePath == " /" then
112
- u
127
+ path
113
128
114
129
else
115
- { u | path = String . replace basePath " " u. path }
130
+ String . replace basePath " " path
131
+
132
+ ensureSlashPrefix path =
133
+ if String . startsWith " /" path then
134
+ path
135
+
136
+ else
137
+ " /" ++ path
116
138
117
139
parse url_ =
118
140
Result . withDefault ( Perspective ( ByCodebase Relative )) ( Parser . run toRoute url_)
119
141
in
120
142
url
121
- |> stripBasePath
122
143
|> . path
144
+ |> stripBasePath
145
+ |> ensureSlashPrefix
123
146
|> parse
124
147
125
148
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ fromUrlBasePath =
188
188
\ _ ->
189
189
let
190
190
url =
191
- mkUrl " /latest/terms/@abc123"
191
+ mkUrl " /some-token/ui/ latest/terms/@abc123"
192
192
193
193
basePath =
194
194
" /some-token/ui/"
You can’t perform that action at this time.
0 commit comments