@@ -325,38 +325,16 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
325
325
$ labels ->push ('traefik.http.middlewares.gzip.compress=true ' );
326
326
$ labels ->push ('traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https ' );
327
327
328
- $ basic_auth = false ;
329
- $ basic_auth_middleware = null ;
330
- $ redirect = false ;
331
- $ redirect_middleware = null ;
328
+ $ middlewares_from_labels = collect ([]);
332
329
333
330
if ($ serviceLabels ) {
334
- $ basic_auth = $ serviceLabels ->contains (function ($ value ) {
335
- return str_contains ($ value , 'basicauth ' );
336
- });
337
- if ($ basic_auth ) {
338
- $ basic_auth_middleware = $ serviceLabels
339
- ->map (function ($ item ) {
340
- if (preg_match ('/traefik\.http\.middlewares\.(.*?)\.basicauth\.users/ ' , $ item , $ matches )) {
341
- return $ matches [1 ];
342
- }
343
- })
344
- ->filter ()
345
- ->first ();
346
- }
347
- $ redirect = $ serviceLabels ->contains (function ($ value ) {
348
- return str_contains ($ value , 'redirectregex ' );
349
- });
350
- if ($ redirect ) {
351
- $ redirect_middleware = $ serviceLabels
352
- ->map (function ($ item ) {
353
- if (preg_match ('/traefik\.http\.middlewares\.(.*?)\.redirectregex\.regex/ ' , $ item , $ matches )) {
354
- return $ matches [1 ];
355
- }
356
- })
357
- ->filter ()
358
- ->first ();
359
- }
331
+ $ middlewares_from_labels = $ serviceLabels ->map (function ($ item ) {
332
+ if (preg_match ('/traefik\.http\.middlewares\.(.*?)(\.|$)/ ' , $ item , $ matches )) {
333
+ return $ matches [1 ];
334
+ }
335
+ return null ;
336
+ })->filter ()
337
+ ->unique ();
360
338
}
361
339
foreach ($ domains as $ loop => $ domain ) {
362
340
try {
@@ -404,31 +382,29 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
404
382
$ labels ->push ("traefik.http.services. {$ https_label }.loadbalancer.server.port= $ port " );
405
383
}
406
384
if ($ path !== '/ ' ) {
385
+ // Middleware handling
407
386
$ middlewares = collect ([]);
408
- if ($ is_stripprefix_enabled && ! str ($ image )->contains ('ghost ' )) {
387
+ if ($ is_stripprefix_enabled && !str ($ image )->contains ('ghost ' )) {
409
388
$ labels ->push ("traefik.http.middlewares. {$ https_label }-stripprefix.stripprefix.prefixes= {$ path }" );
410
389
$ middlewares ->push ("{$ https_label }-stripprefix " );
411
390
}
412
391
if ($ is_gzip_enabled ) {
413
392
$ middlewares ->push ('gzip ' );
414
393
}
415
- if ($ basic_auth && $ basic_auth_middleware ) {
416
- $ middlewares ->push ($ basic_auth_middleware );
417
- }
418
- if ($ redirect && $ redirect_middleware ) {
419
- $ middlewares ->push ($ redirect_middleware );
420
- }
421
394
if (str ($ image )->contains ('ghost ' )) {
422
395
$ middlewares ->push ('redir-ghost ' );
423
396
}
424
397
if ($ redirect_direction === 'non-www ' && str ($ host )->startsWith ('www. ' )) {
425
398
$ labels = $ labels ->merge ($ redirect_to_non_www );
426
399
$ middlewares ->push ($ to_non_www_name );
427
400
}
428
- if ($ redirect_direction === 'www ' && ! str ($ host )->startsWith ('www. ' )) {
401
+ if ($ redirect_direction === 'www ' && !str ($ host )->startsWith ('www. ' )) {
429
402
$ labels = $ labels ->merge ($ redirect_to_www );
430
403
$ middlewares ->push ($ to_www_name );
431
404
}
405
+ $ middlewares_from_labels ->each (function ($ middleware_name ) use ($ middlewares ) {
406
+ $ middlewares ->push ($ middleware_name );
407
+ });
432
408
if ($ middlewares ->isNotEmpty ()) {
433
409
$ middlewares = $ middlewares ->join (', ' );
434
410
$ labels ->push ("traefik.http.routers. {$ https_label }.middlewares= {$ middlewares }" );
@@ -437,13 +413,7 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
437
413
$ middlewares = collect ([]);
438
414
if ($ is_gzip_enabled ) {
439
415
$ middlewares ->push ('gzip ' );
440
- }
441
- if ($ basic_auth && $ basic_auth_middleware ) {
442
- $ middlewares ->push ($ basic_auth_middleware );
443
- }
444
- if ($ redirect && $ redirect_middleware ) {
445
- $ middlewares ->push ($ redirect_middleware );
446
- }
416
+ }
447
417
if (str ($ image )->contains ('ghost ' )) {
448
418
$ middlewares ->push ('redir-ghost ' );
449
419
}
@@ -455,6 +425,9 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
455
425
$ labels = $ labels ->merge ($ redirect_to_www );
456
426
$ middlewares ->push ($ to_www_name );
457
427
}
428
+ $ middlewares_from_labels ->each (function ($ middleware_name ) use ($ middlewares ) {
429
+ $ middlewares ->push ($ middleware_name );
430
+ });
458
431
if ($ middlewares ->isNotEmpty ()) {
459
432
$ middlewares = $ middlewares ->join (', ' );
460
433
$ labels ->push ("traefik.http.routers. {$ https_label }.middlewares= {$ middlewares }" );
@@ -490,12 +463,6 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
490
463
if ($ is_gzip_enabled ) {
491
464
$ middlewares ->push ('gzip ' );
492
465
}
493
- if ($ basic_auth && $ basic_auth_middleware ) {
494
- $ middlewares ->push ($ basic_auth_middleware );
495
- }
496
- if ($ redirect && $ redirect_middleware ) {
497
- $ middlewares ->push ($ redirect_middleware );
498
- }
499
466
if (str ($ image )->contains ('ghost ' )) {
500
467
$ middlewares ->push ('redir-ghost ' );
501
468
}
@@ -507,6 +474,9 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
507
474
$ labels = $ labels ->merge ($ redirect_to_www );
508
475
$ middlewares ->push ($ to_www_name );
509
476
}
477
+ $ middlewares_from_labels ->each (function ($ middleware_name ) use ($ middlewares ) {
478
+ $ middlewares ->push ($ middleware_name );
479
+ });
510
480
if ($ middlewares ->isNotEmpty ()) {
511
481
$ middlewares = $ middlewares ->join (', ' );
512
482
$ labels ->push ("traefik.http.routers. {$ http_label }.middlewares= {$ middlewares }" );
@@ -516,12 +486,6 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
516
486
if ($ is_gzip_enabled ) {
517
487
$ middlewares ->push ('gzip ' );
518
488
}
519
- if ($ basic_auth && $ basic_auth_middleware ) {
520
- $ middlewares ->push ($ basic_auth_middleware );
521
- }
522
- if ($ redirect && $ redirect_middleware ) {
523
- $ middlewares ->push ($ redirect_middleware );
524
- }
525
489
if (str ($ image )->contains ('ghost ' )) {
526
490
$ middlewares ->push ('redir-ghost ' );
527
491
}
@@ -533,6 +497,9 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
533
497
$ labels = $ labels ->merge ($ redirect_to_www );
534
498
$ middlewares ->push ($ to_www_name );
535
499
}
500
+ $ middlewares_from_labels ->each (function ($ middleware_name ) use ($ middlewares ) {
501
+ $ middlewares ->push ($ middleware_name );
502
+ });
536
503
if ($ middlewares ->isNotEmpty ()) {
537
504
$ middlewares = $ middlewares ->join (', ' );
538
505
$ labels ->push ("traefik.http.routers. {$ http_label }.middlewares= {$ middlewares }" );
0 commit comments