How to force SSL in all routes at once?

Notice: This thread is very old.
Honza Kuchař
Member | 1662
+
0
-

Hi there!

Usually I want to have:

  • non-ssl connections on localhost
  • ssl connection on production. (also enabled HTTP Strict Transport Security, currently I add .htaccess to achieve that)

Do I need to have two routers to just generate routes with different flag (https://doc.nette.org/…tion/routing#…

Thanks folks!

Jan Tvrdík
Nette guru | 2595
+
+2
-

One router should be enough, see https://github.com/…rFactory.php for example.

Last edited by Jan Tvrdík (2014-11-16 14:07)

Honza Kuchař
Member | 1662
+
0
-

Thanks! I thought there is something like one-line solution.

bazo
Member | 620
+
0
-

easiest is to use a self signed cert on localhost

Filip Procházka
Moderator | 4668
+
+2
-

My solution is to have it conditional for production

class RouterFactory
{
	private $productionMode;

	public function __construct($productionMode)
	{
		$this->productionMode = $productionMode;
	}

	public function createRouter()
	{
		$router = new RouteList();
		$flags = $this->productionMode ? Route::SECURED : 0;

		$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default', $flags);

		return $router;
	}

}

Last edited by Filip Procházka (2014-11-17 17:04)

Honza Kuchař
Member | 1662
+
0
-

I don't like this way, because I wanted to have it as one-line code. But I acknowledge that on some sites they use encryption just for few requests. (e.g. seznam.cz)

Don't you think there should be something like enable HSTS in Nette?

Honza Kuchař
Member | 1662
+
0
-

Created new thread for this.