Skip to content

Commit 1915aa6

Browse files
committed
Merge branch 'dev'
2 parents 45250c8 + ea72c6e commit 1915aa6

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44
"description": "A simple file-server component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
55
"keywords": [
66
"file-server",
7-
"cocreate",
8-
"low-code-framework",
9-
"no-code-framework",
10-
"cocreatejs",
11-
"cocreatejs-component",
12-
"cocreate-framework",
13-
"no-code",
147
"low-code",
15-
"collaborative-framework",
168
"realtime",
179
"realtime-framework",
1810
"collaboration",

src/index.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class CoCreateFileSystem {
2626
this.sitemap = sitemap;
2727
}
2828

29-
async send(req, res, crud, organization, valideUrl) {
29+
async send(req, res, crud, organization, urlObject) {
3030
try {
31-
const hostname = valideUrl.hostname;
31+
const hostname = urlObject.hostname;
3232

3333
let data = {
3434
method: "object.read",
@@ -72,12 +72,12 @@ class CoCreateFileSystem {
7272
});
7373
}
7474

75-
let parameters = valideUrl.searchParams;
75+
let parameters = urlObject.searchParams;
7676
if (parameters.size) {
7777
console.log("parameters", parameters);
7878
}
7979

80-
let pathname = valideUrl.pathname;
80+
let pathname = urlObject.pathname;
8181

8282
if (pathname.endsWith("/")) {
8383
pathname += "index.html";
@@ -86,7 +86,17 @@ class CoCreateFileSystem {
8686
if (!directory.includes(".")) pathname += "/index.html";
8787
}
8888

89-
data.$filter.query.pathname = pathname;
89+
const bcp47Regex = /^\/([a-zA-Z]{2,3}(?:-[a-zA-Z0-9]{2,8})+)\//;
90+
const match = pathname.match(bcp47Regex);
91+
let lang, langRegion;
92+
if (match) {
93+
langRegion = match[1];
94+
lang = langRegion.split("-")[0]; // Get just the base language (e.g., 'en', 'es', 'fr')
95+
let newPathname = pathname.replace(langRegion, lang);
96+
data.$filter.query.pathname = { $in: [newPathname, pathname] };
97+
} else {
98+
data.$filter.query.pathname = pathname;
99+
}
90100

91101
let file;
92102
if (
@@ -99,12 +109,15 @@ class CoCreateFileSystem {
99109
"/manifest.webmanifest",
100110
"/service-worker.js"
101111
].includes(pathname)
102-
)
112+
) {
103113
file = await getDefaultFile(pathname);
104-
else file = await crud.send(data);
114+
} else {
115+
file = await crud.send(data);
116+
}
105117

118+
// --- Wildcard fallback ---
106119
if (!file || !file.object || !file.object[0]) {
107-
pathname = valideUrl.pathname;
120+
pathname = urlObject.pathname;
108121
let lastIndex = pathname.lastIndexOf("/");
109122
let wildcardPath = pathname.substring(0, lastIndex + 1);
110123
let wildcard = pathname.substring(lastIndex + 1);
@@ -137,8 +150,9 @@ class CoCreateFileSystem {
137150
}
138151

139152
let src;
140-
if (file["src"]) src = file["src"];
141-
else {
153+
if (file["src"]) {
154+
src = file["src"];
155+
} else {
142156
let fileSrc = await crud.send({
143157
method: "object.read",
144158
host: hostname,
@@ -179,11 +193,14 @@ class CoCreateFileSystem {
179193
src = Buffer.from(src, "base64");
180194
} else if (contentType === "text/html") {
181195
try {
182-
src = await this.render.HTML(
183-
src,
184-
organization_id,
185-
valideUrl
186-
);
196+
file.urlObject = urlObject;
197+
if (langRegion) {
198+
file.langRegion = langRegion;
199+
}
200+
if (lang) {
201+
file.lang = lang;
202+
}
203+
src = await this.render.HTML(file);
187204
} catch (err) {
188205
console.warn("server-side-render: " + err.message);
189206
}

0 commit comments

Comments
 (0)