anbaric-web 1.51.0 → 1.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/appInternalPath.ts +18 -7
package/package.json
CHANGED
package/src/appInternalPath.ts
CHANGED
|
@@ -15,15 +15,26 @@ const KNOWN_PREFIXES = ["/api", "/app"];
|
|
|
15
15
|
const isKnownPrefix = (pathname : string) : boolean =>
|
|
16
16
|
KNOWN_PREFIXES.some(prefix => pathname === prefix || pathname.startsWith(`${prefix}/`));
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const isAbsoluteUrl = (value : string) : boolean => /^[a-z][a-z0-9+.-]*:/i.test(value) || value.startsWith("//");
|
|
19
|
+
|
|
20
|
+
/* Places a path onto the named app at /app/<appName>/<path>, or returns
|
|
21
|
+
undefined (leave it untouched) when there is no app, the value is a
|
|
22
|
+
fully-qualified URL, or it is already under a known platform prefix
|
|
23
|
+
(/api, /app - including an already-correct /app/... ).
|
|
24
|
+
|
|
25
|
+
A path without a leading slash is treated as app-relative rather than
|
|
26
|
+
refused. App authors are told to prefer relative links, precisely because
|
|
27
|
+
the app is mounted on a sub-path, so refusing them sent every such Await
|
|
28
|
+
link to the console root - the one shape the guidance asks for was the one
|
|
29
|
+
shape this would not rewrite. */
|
|
22
30
|
const appInternalPath = (appName : string | undefined, pathname : string, search : string = "") : string | undefined => {
|
|
23
31
|
if (!appName) return undefined;
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
if (isAbsoluteUrl(pathname)) return undefined;
|
|
33
|
+
|
|
34
|
+
const absolute = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
35
|
+
if (isKnownPrefix(absolute)) return undefined;
|
|
36
|
+
|
|
37
|
+
return `/app/${appName}${absolute}${search}`;
|
|
27
38
|
};
|
|
28
39
|
|
|
29
40
|
/* The same rule for a whole URL string (path plus any query/hash), returning the
|