Latte links without HTTPS
- sjiamnocna
- Member | 28
Hi,
I've got project using Latte and default Nette structure. It's in docker
container – PHP8.2-FPM proxied by Nginx.
My problem is, that when I run it on localhost, it gives me links with HTTPS:// so I cannot use it, because HTTPS on localhost won't work anyway.
I'd like to remove HTTPS when either I use .local domain (development redirected by /etc/hosts file) or if it's not possible if $_SERVER[‘DEVELOPMENT’] is set (or the Debugger is ON, it's equivalent).
How do I do it?
- nightfish
- Member | 517
@sjiamnocna How do you generate links in the template? How does your router look like?
AFAIK Nette usually generates http://
when you are on
http://
and https://
links when you are on
https://
. The only notable difference being when you are behind a
HTTPS-stripping reverse proxy server – you then need to configure
it – but that is the exact opposite of your problem, so unlikely a
solution.
- sjiamnocna
- Member | 28
Well, that's maybe another possible problem – after upgrade (it's old app almost same from PHP 5.6 and we migrate to 8.2), we'll be running Nginx with some simple settings GUI to proxy to Nginx container that FPMs to PHP-FPM and serves static files. So it would be great I could control HTTPS links by some option in router.
final class RouterFactory
{
use Nette\StaticClass;
public static function createRouter(EnvironmentService $environmentService): RouteList
{
$router = new RouteList;
if ($environmentService->getSubdomain() !== 'n') {
/* public web */
$router
->addRoute('jak-to-funguje', 'Front:Www:Static:about')
->addRoute('cenik', 'Front:Www:Static:pricing')
// ... the same items with different links
->addRoute('caste-dotazy', 'Front:Www:Static:faq')
->addRoute('podminky-sluzeb', 'Front:Www:Static:termsAndConditions')
->addRoute('ochrana-osobnich-udaju', 'Front:Www:Static:privacyPolicy')
->addRoute('/', 'Front:Www:Homepage:default');
} else {
/** client zone **/
$router/*->withDomain('n.%sld%.%tld%')*/
->addRoute('prihlaseni', 'Front:Www:Account:login')
->addRoute('registrace', 'Front:Www:Account:register')
// ...
->addRoute('podminky-sluzeb', 'Front:Www:Static:termsAndConditions')
->addRoute('ochrana-osobnich-udaju', 'Front:Www:Static:privacyPolicy')
->addRoute('admin/<presenter>/<action>[/<id>]', ['module' => 'Admin', 'presenter' => 'Dashboard', 'action' => 'default']);
}
return $router;
}
}
And in common.neon:
services:
# Service
router: App\Router\RouterFactory::createRouter()
Last edited by sjiamnocna (2023-01-12 15:25)
- David Grudl
- Nette Core | 8218
As a hack you can do at the beginning of the
script unset($_SERVER['HTTPS']);
- sjiamnocna
- Member | 28
Found it, was hardcoded using template variable, not using router links
anyway.
Men I love legacy code :D
Thanks for advice. Have a nice day :)