1

How to configure a Ninja web application running on Heroku to force the use of SSL, that is, redirect all requests to HTTPS?

Patrick
  • 3,578
  • 5
  • 31
  • 53

2 Answers2

1

Here is the class to add in the conf package:

public class Filters implements ApplicationFilters {
  @Override
  public void addFilters (List<Class<? extends Filter>> list) {
    list.add (HttpsFilter.class);
  }
  public static class HttpsFilter implements Filter {
    @Override
    public Result filter (FilterChain filterChain, Context context) {
      if ("http".equals (context.getHeader ("X-Forwarded-Proto"))) {
        return Results.redirect ("https://" + context.getHostname ()
          + context.getRequestPath ());
      }
      return filterChain.next (context);
    }
  }
}
Patrick
  • 3,578
  • 5
  • 31
  • 53
-1

If you look good in the ninja framework documentation it is indicated how to configure it to get what you want

http://www.ninjaframework.org/documentation/configuration_and_modes.html