Skip to content

Instantly share code, notes, and snippets.

View samritbk's full-sized avatar

Beraki Befekadu samritbk

  • Calgary, Alberta
View GitHub Profile
@samritbk
samritbk / SparkRedirect.java
Created July 21, 2018 14:19
Remove / in Spark Java (Allow with / and without /)
Spark.before((req, res) -> {
String path = req.pathInfo();
if (path.endsWith("/") && path.length() != 1) // length prevents redirect on homepage http://example.com/ <--
res.redirect(path.substring(0, path.length() - 1));
});