@@ -79,6 +79,11 @@ const (
79
79
" For CouchDB, include the username:password@ text if required." +
80
80
" Alternatively, this can be set with the following environment variable: " + databaseURLEnvKey
81
81
82
+ staticFilesPathFlagName = "static-path"
83
+ staticFilesPathFlagUsage = "Path to the folder where the static files are to be hosted under " + uiEndpoint + "." +
84
+ "Alternatively, this can be set with the following environment variable: " + staticFilesPathEnvKey
85
+ staticFilesPathEnvKey = "AUTH_REST_STATIC_FILES"
86
+
82
87
databasePrefixFlagName = "database-prefix"
83
88
databasePrefixEnvKey = "AUTH_REST_DATABASE_PREFIX"
84
89
databasePrefixFlagShorthand = "p"
@@ -129,6 +134,7 @@ const (
129
134
130
135
const (
131
136
// api
137
+ uiEndpoint = "/ui"
132
138
healthCheckEndpoint = "/healthcheck"
133
139
)
134
140
@@ -143,6 +149,7 @@ type authRestParameters struct {
143
149
tlsParams * tlsParams
144
150
oidcParams * oidcParams
145
151
bootstrapParams * bootstrapParams
152
+ staticFiles string
146
153
}
147
154
148
155
type tlsParams struct {
@@ -210,7 +217,7 @@ func createStartCmd(srv server) *cobra.Command {
210
217
}
211
218
}
212
219
213
- func getAuthRestParameters (cmd * cobra.Command ) (* authRestParameters , error ) {
220
+ func getAuthRestParameters (cmd * cobra.Command ) (* authRestParameters , error ) { //nolint:funlen,gocyclo
214
221
hostURL , err := cmdutils .GetUserSetVarFromString (cmd , hostURLFlagName , hostURLEnvKey , false )
215
222
if err != nil {
216
223
return nil , err
@@ -231,6 +238,11 @@ func getAuthRestParameters(cmd *cobra.Command) (*authRestParameters, error) {
231
238
return nil , err
232
239
}
233
240
241
+ staticFiles , err := cmdutils .GetUserSetVarFromString (cmd , staticFilesPathFlagName , staticFilesPathEnvKey , true )
242
+ if err != nil {
243
+ return nil , err
244
+ }
245
+
234
246
var databaseURL string
235
247
if databaseType == databaseTypeMemOption {
236
248
databaseURL = "N/A"
@@ -266,6 +278,7 @@ func getAuthRestParameters(cmd *cobra.Command) (*authRestParameters, error) {
266
278
databasePrefix : databasePrefix ,
267
279
oidcParams : oidcParams ,
268
280
bootstrapParams : bootstrapParams ,
281
+ staticFiles : staticFiles ,
269
282
}, nil
270
283
}
271
284
@@ -311,6 +324,7 @@ func createFlags(startCmd *cobra.Command) {
311
324
startCmd .Flags ().StringP (tlsServeCertPathFlagName , "" , "" , tlsServeCertPathFlagUsage )
312
325
startCmd .Flags ().StringP (tlsServeKeyPathFlagName , "" , "" , tlsServeKeyPathFlagUsage )
313
326
startCmd .Flags ().StringP (logLevelFlagName , logLevelFlagShorthand , "" , logLevelPrefixFlagUsage )
327
+ startCmd .Flags ().StringP (staticFilesPathFlagName , "" , "" , staticFilesPathFlagUsage )
314
328
startCmd .Flags ().StringP (databaseTypeFlagName , databaseTypeFlagShorthand , "" , databaseTypeFlagUsage )
315
329
startCmd .Flags ().StringP (databaseURLFlagName , databaseURLFlagShorthand , "" , databaseURLFlagUsage )
316
330
startCmd .Flags ().StringP (databasePrefixFlagName , databasePrefixFlagShorthand , "" , databasePrefixFlagUsage )
@@ -340,7 +354,6 @@ func startAuthService(parameters *authRestParameters, srv server) error {
340
354
logger .Debugf ("root ca's %v" , rootCAs )
341
355
342
356
router := mux .NewRouter ()
343
-
344
357
// health check
345
358
router .HandleFunc (healthCheckEndpoint , healthCheckHandler ).Methods (http .MethodGet )
346
359
@@ -368,12 +381,16 @@ func startAuthService(parameters *authRestParameters, srv server) error {
368
381
router .HandleFunc (handler .Path (), handler .Handle ()).Methods (handler .Method ())
369
382
}
370
383
371
- logger .Infof (`Starting hub-auth REST server with the following parameters:
372
- Host URL: %s
373
- Database type: %s
384
+ logger .Infof (`Starting hub-auth REST server with the following parameters:Host URL: %s Database type: %s
374
385
Database URL: %s
375
386
Database prefix: %s` , parameters .hostURL , parameters .databaseType , parameters .databaseURL , parameters .databasePrefix )
376
387
388
+ // static frontend
389
+ router .PathPrefix (uiEndpoint ).
390
+ Subrouter ().
391
+ Methods (http .MethodGet ).
392
+ HandlerFunc (uiHandler (parameters .staticFiles , http .ServeFile ))
393
+
377
394
return srv .ListenAndServeTLS (
378
395
parameters .hostURL ,
379
396
parameters .tlsParams .serveCertPath ,
@@ -382,6 +399,19 @@ Database prefix: %s`, parameters.hostURL, parameters.databaseType, parameters.da
382
399
)
383
400
}
384
401
402
+ func uiHandler (
403
+ basePath string ,
404
+ fileServer func (http.ResponseWriter , * http.Request , string )) func (http.ResponseWriter , * http.Request ) {
405
+ return func (w http.ResponseWriter , r * http.Request ) {
406
+ if r .URL .Path == uiEndpoint {
407
+ fileServer (w , r , strings .ReplaceAll (basePath + "/index.html" , "//" , "/" ))
408
+ return
409
+ }
410
+
411
+ fileServer (w , r , strings .ReplaceAll (basePath + "/" + r .URL .Path [len (uiEndpoint ):], "//" , "/" ))
412
+ }
413
+ }
414
+
385
415
func getOIDCParams (cmd * cobra.Command ) (* oidcParams , error ) {
386
416
params := & oidcParams {}
387
417
0 commit comments