From e48affacb8d1e67c06c2de4e87e50764111f459d Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sun, 19 Nov 2023 09:35:59 +1100 Subject: [PATCH] Redirect routes with trailing slashes See: https://github.com/hanami/router/issues/256 --- Gemfile | 1 + Gemfile.lock | 2 ++ config.ru | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index d16a2bc..8b949e4 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem "gnuplot" gem "matrix" gem "rack-session" +gem "rack-rewrite" gem "ruby-readability", require: "readability" gem "down" diff --git a/Gemfile.lock b/Gemfile.lock index bf5fb01..9da9acc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -330,6 +330,7 @@ GEM que (2.3.0) racc (1.7.3) rack (2.2.8) + rack-rewrite (1.5.1) rack-session (1.0.1) rack (< 3) rack-test (2.1.0) @@ -517,6 +518,7 @@ DEPENDENCIES pinboard! puma que + rack-rewrite rack-session rack-test rake diff --git a/config.ru b/config.ru index b84bd83..7a75380 100644 --- a/config.ru +++ b/config.ru @@ -12,4 +12,10 @@ use Rack::Session::Cookie, :expire_after => 3600*24, :secret => ENV["SESSION_SECRET"] +require "rack/rewrite" +use Rack::Rewrite do + # remove trailing slashes + r302 %r{(/.*)/(\?.*)?$}, "$1$2" +end + run Hanami.app