@@ -96,6 +96,16 @@ export class SidequestDashboard {
9696 ...config ,
9797 } ;
9898
99+ // Normalize basePath: remove trailing slash, ensure leading slash
100+ if ( this . config . basePath ) {
101+ this . config . basePath = this . config . basePath . replace ( / \/ $ / , "" ) ;
102+ if ( ! this . config . basePath . startsWith ( "/" ) ) {
103+ this . config . basePath = "/" + this . config . basePath ;
104+ }
105+ } else {
106+ this . config . basePath = "" ;
107+ }
108+
99109 if ( ! this . config . enabled ) {
100110 logger ( "Dashboard" ) . debug ( `Dashboard is disabled` ) ;
101111 return ;
@@ -128,6 +138,12 @@ export class SidequestDashboard {
128138 if ( logger ( ) . isDebugEnabled ( ) ) {
129139 this . app ?. use ( morgan ( "combined" ) ) ;
130140 }
141+
142+ // Make basePath available to all templates
143+ this . app ?. use ( ( req , res , next ) => {
144+ res . locals . basePath = this . config ! . basePath ?? "" ;
145+ next ( ) ;
146+ } ) ;
131147 }
132148
133149 /**
@@ -180,7 +196,8 @@ export class SidequestDashboard {
180196 this . app ! . set ( "view engine" , "ejs" ) ;
181197 this . app ! . set ( "views" , path . join ( import . meta. dirname , "views" ) ) ;
182198 this . app ! . set ( "layout" , path . join ( import . meta. dirname , "views" , "layout" ) ) ;
183- this . app ! . use ( "/public" , express . static ( path . join ( import . meta. dirname , "public" ) ) ) ;
199+ const publicPath = this . config ! . basePath ? `${ this . config ! . basePath } /public` : "/public" ;
200+ this . app ! . use ( publicPath , express . static ( path . join ( import . meta. dirname , "public" ) ) ) ;
184201 }
185202
186203 /**
@@ -195,9 +212,14 @@ export class SidequestDashboard {
195212 */
196213 setupRoutes ( ) {
197214 logger ( "Dashboard" ) . debug ( `Setting up routes` ) ;
198- this . app ! . use ( ...createDashboardRouter ( this . backend ! ) ) ;
199- this . app ! . use ( ...createJobsRouter ( this . backend ! ) ) ;
200- this . app ! . use ( ...createQueuesRouter ( this . backend ! ) ) ;
215+ const basePath = this . config ! . basePath ?? "" ;
216+ const [ dashboardPath , dashboardRouter ] = createDashboardRouter ( this . backend ! ) ;
217+ const [ jobsPath , jobsRouter ] = createJobsRouter ( this . backend ! ) ;
218+ const [ queuesPath , queuesRouter ] = createQueuesRouter ( this . backend ! ) ;
219+
220+ this . app ! . use ( basePath + dashboardPath , dashboardRouter ) ;
221+ this . app ! . use ( basePath + jobsPath , jobsRouter ) ;
222+ this . app ! . use ( basePath + queuesPath , queuesRouter ) ;
201223 }
202224
203225 /**
0 commit comments