How to force SSL in all routes at once?

Notice: This thread is very old.
Honza Kuchař
Backer | 1657
+
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/en/2.4/routing#…

Thanks folks!

Jan Tvrdík
Nette guru | 2563
+
+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)

Comments

Honza Kuchař:

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

6 years ago
Filip Procházka
Moderator | 4693
+
+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)

Comments

Honza Kuchař:

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?

6 years ago
Honza Kuchař:

Created new thread for this.

6 years ago
bazo
Member | 625
+
0
-

easiest is to use a self signed cert on localhost