如何禁用 Heroku and/or 上的 HTTP 请求自动重定向到 HTTPS?

How to disable HTTP requests on Heroku and/or auto-redirect to HTTPS?

我目前正在部署 Scala Play 2。7.x 应用程序到 Heroku,仅打算进行 HTTPS 访问,但 HTTP 访问仍然可用,然后在这种情况下,身份验证不起作用。

如何为部署在 Heroku 中的 Scala Play 应用程序完全禁用 HTTP?

Heroku doesn't handle redirection for you:

Redirects need to be performed at the application level as the Heroku router does not provide this functionality. You should code the redirect logic into your application.

看起来这是 relatively straightforward Play Framework 版本 2.6 或更高版本:

play.filters.enabled += play.filters.https.RedirectHttpsFilter

如有必要,您 can override this setting in your development environment by passing -Dplay.filters.enabled=<whatever> locally, or provide an alternate configuration file with -Dconfig.file.