crelte 0.4.0 → 0.4.1
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/dist/routing/InnerRouter.d.ts.map +1 -1
- package/dist/routing/InnerRouter.js +2 -18
- package/dist/routing/Site.d.ts +1 -0
- package/dist/routing/Site.d.ts.map +1 -1
- package/dist/routing/Site.js +20 -0
- package/dist/routing/internal.d.ts +3 -0
- package/dist/routing/internal.d.ts.map +1 -0
- package/dist/routing/internal.js +2 -0
- package/package.json +5 -1
- package/src/routing/InnerRouter.ts +2 -20
- package/src/routing/Site.ts +24 -0
- package/src/routing/internal.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InnerRouter.d.ts","sourceRoot":"","sources":["../../src/routing/InnerRouter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"InnerRouter.d.ts","sourceRoot":"","sources":["../../src/routing/InnerRouter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAC/D,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,OAAO,EAAE,EAAa,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,MAAM,eAAe,GAAG;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd;;;;;OAKG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC7D,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAEpC,OAAO,CAAC,qBAAqB,CAAa;IAE1C;;;;;OAKG;gBACS,KAAK,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe;IAkB3D;;OAEG;IACH,UAAU;IAgBV;;OAEG;IACH,UAAU;IAEV;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,GAAE,MAAM,GAAG,IAAW,GAAG,IAAI;IAsCxD;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAKjC;;;;;;OAMG;IACH,eAAe,CACd,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO,EACtC,IAAI,GAAE,cAAmB,GACvB,OAAO;IA0BV;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK;IAcjC,MAAM;IAoGN;;;;;;;;;OASG;IACH,IAAI,CAAC,GAAG,EAAE,OAAO;IA4CjB;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,EAAE,OAAO;IAuBjB;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,OAAO;IAuBpB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO;IAW9C,QAAQ,CAAC,GAAG,EAAE,OAAO;CAsErB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Site from './Site.js';
|
|
1
|
+
import Site, { siteFromUrl } from './Site.js';
|
|
2
2
|
import { ClientHistory, ServerHistory } from './History.js';
|
|
3
3
|
import Request, { isRequest } from './Request.js';
|
|
4
4
|
import Route from './Route.js';
|
|
@@ -155,23 +155,7 @@ export default class InnerRouter {
|
|
|
155
155
|
// strip stuff we dont need from url
|
|
156
156
|
const route = new Route(fullUrl, null);
|
|
157
157
|
const url = route.url;
|
|
158
|
-
|
|
159
|
-
// get the site which matches the url the most
|
|
160
|
-
for (const s of this.sites) {
|
|
161
|
-
const siteUri = s.uri;
|
|
162
|
-
// make sure the start of the url matches
|
|
163
|
-
if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
// make sure that after the base url a slash follows or nothing
|
|
167
|
-
const uri = url.pathname.substring(siteUri.length);
|
|
168
|
-
if (uri.length > 0 && !uri.startsWith('/'))
|
|
169
|
-
continue;
|
|
170
|
-
/// make sure we get the most matched site
|
|
171
|
-
if (site && site.uri.length > siteUri.length)
|
|
172
|
-
continue;
|
|
173
|
-
site = s;
|
|
174
|
-
}
|
|
158
|
+
const site = siteFromUrl(url, this.sites);
|
|
175
159
|
// todo should we throw if we can't find a site
|
|
176
160
|
// or use the site which matches the language
|
|
177
161
|
route.site = site ?? this.defaultSite();
|
package/dist/routing/Site.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Site.d.ts","sourceRoot":"","sources":["../../src/routing/Site.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;gBAEL,GAAG,EAAE,eAAe;IAShC;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;CACD"}
|
|
1
|
+
{"version":3,"file":"Site.d.ts","sourceRoot":"","sources":["../../src/routing/Site.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAI;IACxB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;gBAEL,GAAG,EAAE,eAAe;IAShC;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;CACD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAsBhE"}
|
package/dist/routing/Site.js
CHANGED
|
@@ -46,3 +46,23 @@ export default class Site {
|
|
|
46
46
|
return trimSlashEnd(this.url.pathname);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
export function siteFromUrl(url, sites) {
|
|
50
|
+
let site = null;
|
|
51
|
+
// get the site which matches the url the most
|
|
52
|
+
for (const s of sites) {
|
|
53
|
+
const siteUri = s.uri;
|
|
54
|
+
// make sure the start of the url matches
|
|
55
|
+
if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// make sure that after the base url a slash follows or nothing
|
|
59
|
+
const uri = url.pathname.substring(siteUri.length);
|
|
60
|
+
if (uri.length > 0 && !uri.startsWith('/'))
|
|
61
|
+
continue;
|
|
62
|
+
/// make sure we get the most matched site
|
|
63
|
+
if (site && site.uri.length > siteUri.length)
|
|
64
|
+
continue;
|
|
65
|
+
site = s;
|
|
66
|
+
}
|
|
67
|
+
return site;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/routing/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crelte",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"author": "Crelte <support@crelte.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"types": "./dist/routing/index.d.ts",
|
|
45
45
|
"default": "./dist/routing/index.js"
|
|
46
46
|
},
|
|
47
|
+
"./routing/internal": {
|
|
48
|
+
"types": "./dist/routing/internal.d.ts",
|
|
49
|
+
"default": "./dist/routing/internal.js"
|
|
50
|
+
},
|
|
47
51
|
"./entry": {
|
|
48
52
|
"types": "./dist/entry/index.d.ts",
|
|
49
53
|
"default": "./dist/entry/index.js"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Site, { SiteFromGraphQl } from './Site.js';
|
|
1
|
+
import Site, { SiteFromGraphQl, siteFromUrl } from './Site.js';
|
|
2
2
|
import History from './History.js';
|
|
3
3
|
import { ClientHistory, ServerHistory } from './History.js';
|
|
4
4
|
import Request, { isRequest, RequestOptions } from './Request.js';
|
|
@@ -184,25 +184,7 @@ export default class InnerRouter {
|
|
|
184
184
|
const route = new Route(fullUrl, null!);
|
|
185
185
|
const url = route.url;
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
// get the site which matches the url the most
|
|
189
|
-
for (const s of this.sites) {
|
|
190
|
-
const siteUri = s.uri;
|
|
191
|
-
|
|
192
|
-
// make sure the start of the url matches
|
|
193
|
-
if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// make sure that after the base url a slash follows or nothing
|
|
198
|
-
const uri = url.pathname.substring(siteUri.length);
|
|
199
|
-
if (uri.length > 0 && !uri.startsWith('/')) continue;
|
|
200
|
-
|
|
201
|
-
/// make sure we get the most matched site
|
|
202
|
-
if (site && site.uri.length > siteUri.length) continue;
|
|
203
|
-
|
|
204
|
-
site = s;
|
|
205
|
-
}
|
|
187
|
+
const site = siteFromUrl(url, this.sites);
|
|
206
188
|
|
|
207
189
|
// todo should we throw if we can't find a site
|
|
208
190
|
// or use the site which matches the language
|
package/src/routing/Site.ts
CHANGED
|
@@ -63,3 +63,27 @@ export default class Site {
|
|
|
63
63
|
return trimSlashEnd(this.url.pathname);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
export function siteFromUrl(url: URL, sites: Site[]): Site | null {
|
|
68
|
+
let site: Site | null = null;
|
|
69
|
+
// get the site which matches the url the most
|
|
70
|
+
for (const s of sites) {
|
|
71
|
+
const siteUri = s.uri;
|
|
72
|
+
|
|
73
|
+
// make sure the start of the url matches
|
|
74
|
+
if (url.host !== s.url.host || !url.pathname.startsWith(siteUri)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// make sure that after the base url a slash follows or nothing
|
|
79
|
+
const uri = url.pathname.substring(siteUri.length);
|
|
80
|
+
if (uri.length > 0 && !uri.startsWith('/')) continue;
|
|
81
|
+
|
|
82
|
+
/// make sure we get the most matched site
|
|
83
|
+
if (site && site.uri.length > siteUri.length) continue;
|
|
84
|
+
|
|
85
|
+
site = s;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return site;
|
|
89
|
+
}
|