@@ -14,7 +14,7 @@ import $_console from "views/console.hbs";
1414import $_markdown from "views/markdown.hbs" ;
1515import constants from "./constants" ;
1616import EditorFile from "./editorFile" ;
17- import openFolder from "./openFolder" ;
17+ import openFolder , { addedFolder } from "./openFolder" ;
1818import appSettings from "./settings" ;
1919
2020/**@type {Server } */
@@ -172,14 +172,23 @@ async function run(
172172 * @param {string } req.requestId
173173 * @param {string } req.path
174174 */
175- function handleRequest ( req ) {
175+ async function handleRequest ( req ) {
176176 const reqId = req . requestId ;
177177 let reqPath = req . path . substring ( 1 ) ;
178178
179- if ( ! reqPath || reqPath . endsWith ( "/" ) ) {
180- reqPath += "index.html" ;
179+ //if (!reqPath || reqPath.endsWith("/")) {}
180+
181+ if ( ! reqPath ) {
182+ console . error ( "Request path is empty" ) ;
183+ webServer ?. send ( reqId , {
184+ status : 404 ,
185+ body : "Please provide full path of the file" ,
186+ } ) ;
187+ return ;
181188 }
182189
190+
191+
183192 const ext = Url . extname ( reqPath ) ;
184193 let url = null ;
185194
@@ -250,7 +259,7 @@ async function run(
250259 let file = activeFile . SAFMode === "single" ? activeFile : null ;
251260
252261 if ( pathName ) {
253- url = Url . join ( pathName , reqPath ) ;
262+ url = Url . join ( addedFolder [ 0 ] . url , reqPath ) ;
254263 file = editorManager . getFile ( url , "uri" ) ;
255264 } else if ( ! activeFile . uri ) {
256265 file = activeFile ;
@@ -480,12 +489,18 @@ async function run(
480489 } ) ;
481490 }
482491
492+ function removePrefix ( str , prefix ) {
493+ return str . startsWith ( prefix ) ? str . slice ( prefix . length ) : str ;
494+ }
495+
483496 /**
484497 * Opens the preview in browser
485498 */
486499 function openBrowser ( ) {
487- console . count ( "openBrowser" ) ;
488- const src = `http://localhost:${ port } /${ filename } ` ;
500+ /** @type {string } */
501+ const filePath = pathName + filename ;
502+ let path = removePrefix ( removePrefix ( filePath , addedFolder [ 0 ] . url ) , "/" ) ;
503+ const src = `http://localhost:${ port } /${ path } ` ;
489504 if ( target === "browser" ) {
490505 system . openInBrowser ( src ) ;
491506 return ;
0 commit comments