Skip to content

Commit bdbf86b

Browse files
authored
feat: extensionless URL resolution in preview server (#1824)
1 parent 56c2358 commit bdbf86b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/lib/run.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,41 @@ async function run(
256256
file = activeFile;
257257
}
258258

259+
// Handle extensionless URLs (e.g., "about" -> "about.html" or "about/index.html")
260+
if (!ext && pathName) {
261+
// Try exact match first for extensionless files (LICENSE, README, etc.)
262+
const exactUrl = Url.join(pathName, reqPath);
263+
const exactFs = fsOperation(exactUrl);
264+
if (await exactFs.exists()) {
265+
sendFile(exactUrl, reqId);
266+
return;
267+
}
268+
269+
// Try path.html
270+
const htmlUrl = Url.join(pathName, reqPath + ".html");
271+
const htmlFile = editorManager.getFile(htmlUrl, "uri");
272+
if (htmlFile?.loaded && htmlFile.isUnsaved) {
273+
sendHTML(htmlFile.session?.getValue(), reqId);
274+
return;
275+
}
276+
const htmlFs = fsOperation(htmlUrl);
277+
if (await htmlFs.exists()) {
278+
sendFileContent(htmlUrl, reqId, MIMETYPE_HTML);
279+
return;
280+
}
281+
282+
// Try path/index.html
283+
const indexUrl = Url.join(pathName, reqPath, "index.html");
284+
const indexFs = fsOperation(indexUrl);
285+
if (await indexFs.exists()) {
286+
sendFileContent(indexUrl, reqId, MIMETYPE_HTML);
287+
return;
288+
}
289+
290+
error(reqId);
291+
return;
292+
}
293+
259294
switch (ext) {
260295
case ".htm":
261296
case ".html":

0 commit comments

Comments
 (0)