Skip to content

Commit 58110bf

Browse files
committed
Change ENVIRONMENT='development' to PROXY_MODE env variable for disabling HTTPS
Fixes #16
1 parent 135ac9d commit 58110bf

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

src/Service/RouterService.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ final public function populate() : Router
3939
$strategy->setContainer($container);
4040
$router->setStrategy($strategy);
4141

42-
/*/ Make sure HTTPS is always used in production /*/
43-
$scheme = 'http';
44-
if (getenv('ENVIRONMENT') !== 'development') {
45-
$router->map('GET', '/{page:(?:.|/)*}', HttpToHttpsController::class)->setScheme($scheme);
46-
$scheme = 'https';
42+
/*/ Redirect all HTTP requests to HTTPS, unless we are behind a proxy /*/
43+
if ( ! getenv('PROXY_MODE')) {
44+
$router->map('GET', '/{page:(?:.|/)*}', HttpToHttpsController::class)->setScheme('http');
4745
}
4846

4947
/*/ Map routes and groups /*/
50-
$router->map('GET', '/', HelloWorldController::class)->setScheme($scheme);
51-
$router->group('/profile', $this->createProfileGroup())->setScheme($scheme);
48+
$router->map('GET', '/', HelloWorldController::class);
49+
$router->group('/profile', $this->createProfileGroup());
5250

5351
return $router;
5452
}

web/index.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,35 @@
158158
/*/ Default output is HTML, should return a Response object /*/
159159
$router->setStrategy($strategy);
160160

161-
/*/ Make sure HTTPS is always used in production /*/
162-
$scheme = 'http';
163-
if (getenv('ENVIRONMENT') !== 'development') {
164-
$router->map('GET', '/{page:(?:.|/)*}', HttpToHttpsController::class)->setScheme($scheme);
165-
$scheme = 'https';
161+
/*/ Redirect all HTTP requests to HTTPS, unless we are behind a proxy /*/
162+
if ( ! getenv('PROXY_MODE')) {
163+
$router->map('GET', '/{page:(?:.|/)*}', HttpToHttpsController::class)->setScheme('http');
166164
}
167165

168-
$router->map('GET', '/', HelloWorldController::class)->setScheme($scheme);
166+
$router->map('GET', '/', HelloWorldController::class);
167+
168+
// @FIXME: CORS handling, slash-adding (and possibly others?) should be added as middleware instead of "catchall" URLs map
169169

170170
/*/ Create URI groups /*/
171-
$router->map('GET', '/.well-known/openid-configuration', OpenidController::class)->setScheme($scheme);
172-
$router->map('GET', '/jwks', JwksController::class)->setScheme($scheme);
173-
$router->map('GET', '/login', AddSlashToPathController::class)->setScheme($scheme);
174-
$router->map('GET', '/login/', LoginPageController::class)->setScheme($scheme);
175-
$router->map('POST', '/login', LoginController::class)->setScheme($scheme);
176-
$router->map('POST', '/login/', LoginController::class)->setScheme($scheme);
177-
$router->map('OPTIONS', '/{path}', CorsController::class)->setScheme($scheme);
178-
$router->map('POST', '/register', RegisterController::class)->setScheme($scheme);
179-
$router->map('GET', '/profile', AddSlashToPathController::class)->setScheme($scheme);
180-
$router->map('GET', '/profile/', ProfileController::class)->setScheme($scheme);
181-
$router->map('GET', '/profile/card', CardController::class)->setScheme($scheme);
182-
$router->map('GET', '/profile/card{extension}', CardController::class)->setScheme($scheme);
183-
$router->map('GET', '/authorize', AuthorizeController::class)->setScheme($scheme);
184-
$router->map('GET', '/sharing/{clientId}/', ApprovalController::class)->setScheme($scheme);
185-
$router->map('POST', '/sharing/{clientId}/', HandleApprovalController::class)->setScheme($scheme);
186-
$router->map('POST', '/token', TokenController::class)->setScheme($scheme);
187-
$router->map('POST', '/token/', TokenController::class)->setScheme($scheme);
171+
$router->map('GET', '/login', AddSlashToPathController::class);
172+
$router->map('GET', '/profile', AddSlashToPathController::class);
173+
174+
$router->map('OPTIONS', '/{path:.*}', CorsController::class);
175+
$router->map('GET', '/.well-known/openid-configuration', OpenidController::class);
176+
$router->map('GET', '/jwks', JwksController::class);
177+
$router->map('GET', '/login/', LoginPageController::class);
178+
$router->map('POST', '/login', LoginController::class);
179+
$router->map('POST', '/login/', LoginController::class);
180+
$router->map('POST', '/register', RegisterController::class);
181+
$router->map('GET', '/profile/', ProfileController::class);
182+
$router->map('GET', '/profile/card', CardController::class);
183+
$router->map('GET', '/profile/card{extension}', CardController::class);
184+
$router->map('GET', '/authorize', AuthorizeController::class);
185+
$router->map('GET', '/sharing/{clientId}/', ApprovalController::class);
186+
$router->map('POST', '/sharing/{clientId}/', HandleApprovalController::class);
187+
$router->map('POST', '/token', TokenController::class);
188+
$router->map('POST', '/token/', TokenController::class);
189+
188190
$router->group('/storage', static function (\League\Route\RouteGroup $group) {
189191
$methods = [
190192
'DELETE',
@@ -201,7 +203,7 @@
201203
// $group->map($method, '//', StorageController::class);
202204
$group->map($method, '{path:.*}', ResourceController::class);
203205
});
204-
})->setScheme($scheme);
206+
});
205207

206208
try {
207209
$response = $router->dispatch($request);

0 commit comments

Comments
 (0)