Redirect all trailing slashes globally in express

The answer by Tolga Akyüz is inspiring but doesn’t work if there is any characters after the slash. For example http://example.com/api/?q=a is redirected to http://example.com/api instead of http://example.com/api?q=a. Here is an improved version of the proposed middleware that fixes the problem by adding the original query to the end of the redirect destination URL. The … Read more