Closed tobiascapin closed 2 months ago
Sorry, I just discovered the current UriInterface is used and my server uses http because https is handled by the balancer.
The schema of the request object could be switched using a middleware that you add after the RoutingMiddleware.
$app->addRoutingMiddleware();
$app->add(function(ServerRequestInterface $request, RequestHandlerInterface $handler) {
$request = $request->withUri($request->getUri()->withScheme('https'));
return $handler->handle($request);
});
To get the full url you can use the fullUrlFor
method of the RouteParser instance.
// https://api.example.com/
$fullUrl = $routeParser->fullUrlFor($request->getUri(), 'home', $data, $queryParams);
Great. Thank you very much.
I come back to this topic because it seems getUri()->withScheme('https')
doesn't fill the correct port.
had also to add ->withPort(443)
otherwise some https URL will be made like https://myhost:80/path and doesn't work.
I don't know if I'm missing something or by design withScheme has to go with withPort method.
I'm using urlFor method to get the full URL of a route, but is it not clear to me if it is possibile to set the wanted protocol, it seems always http is given.