@@ -180,10 +180,12 @@ export class Knight {
180180 const router = new Router ( ) ;
181181
182182 // Register all controllers
183+ const orgPath = Deno . cwd ( ) ;
184+ const path = this . cleanPath ( orgPath ) ;
183185 if ( logger ) {
184- logger . debug ( `Searching for controllers in ${ Deno . cwd ( ) } ` ) ;
186+ logger . debug ( `Searching for controllers in ${ path } (from ${ orgPath } ) ` ) ;
185187 }
186- const controllers = await this . findLocalControllersIn ( Deno . cwd ( ) ) ;
188+ const controllers = await this . findLocalControllersIn ( path ) ;
187189 if ( this . _mode == AppMode . DEV && logger ) {
188190 logger . debug ( `Found ${ controllers . length } controllers: ${ controllers . map ( c => c . constructor . name ) . join ( ", " ) } ` ) ;
189191 }
@@ -195,6 +197,27 @@ export class Knight {
195197 return app ;
196198 }
197199
200+ /**
201+ * Extracts local paths wrapped in other protocols, e.g:
202+ * `https://jsr.io/C:/Users/...` -> `file:///C:/Users/...`
203+ * @param path Path to clean (e.g. https://)
204+ * @returns Cleaned path (file://)
205+ */
206+ private static cleanPath ( path : string ) : string {
207+ path = path . replace ( / \\ / g, "/" ) ;
208+ if ( path . startsWith ( "https://" ) ) {
209+ // Find the start index of the local path via `/[a-zA-Z]:\/` and remove up til that index
210+ const match = path . match ( / \/ [ a - z A - Z ] : \/ / ) ;
211+ if ( match ) {
212+ path = path . substring ( match . index ! + 1 ) ;
213+ return `file://${ path } ` ;
214+ } else {
215+ throw new Error ( `Invalid path: ${ path } ` ) ;
216+ }
217+ }
218+ return path ;
219+ }
220+
198221 /**
199222 * Find all controllers in the local project
200223 */
@@ -206,7 +229,7 @@ export class Knight {
206229 const subControllers = await this . findLocalControllersIn ( path ) ;
207230 controllers . push ( ...subControllers ) ;
208231 } else if ( file . isFile && file . name . endsWith ( "Controller.ts" ) ) {
209- const module = await import ( `file:// ${ path } ` ) ;
232+ const module = await import ( path ) ;
210233 const defaultController = module . default ;
211234 // Check that the default controller implements IController
212235 // console.log(module, defaultController);
0 commit comments