Order of route evaluation in Spark

Since you can specify wildcards in Spark's routing settings, there is a possibility that the same URL will match multiple routes. When matching multiple routes, it seems that the one defined earlier has priority.

It can also suffer from static files, but their priority is lower than Java programs. However, only index.html has the highest ranking for some reason. What is this specification?

For example, if you have the following program

python


public class Main {

  public static void main(String[] args) {

    staticFiles.externalLocation(".");

    get("/", (request, response) -> "hello index");
    get("/sample", (request, response) -> "hello sample");
    get("/sample.html", (request, response) -> "hello sample.html");
    get("/:value", (request, response) -> "this is " + request.params("value"));
    get("/sample2", (request, response) -> "hello sample2"); //This is never called
  }
}

The routing is as follows.

/ → If index.html exists in the static file, that will be prioritized. If it does not exist, "hello index" is displayed. /index.html → If index.html exists in the static file, that will be prioritized. If it does not exist, "this is index.html" is displayed. / sample → "hello sample" is displayed. / sample2 → "this is sample2" is displayed. /sample.html → "hello sample.html" is displayed. The static file sample.html is not called.

It's quite complicated.

Recommended Posts

Order of route evaluation in Spark
Order of processing in the program
SaveAsBinaryFile in Spark
[Order method] Set the order of data in Rails
[Ruby] Behavior of evaluation of conditional expression in while
Order of modifiers used in Swift (see SwiftLint)
[Rails] Ranking and pagination in order of likes
Evaluation of logical operators
Output in multiples of 3
Arrange posts in order of likes on Rails (ranking)
Rails sorting function implementation (displayed in order of number of like)
Implementation of gzip in java
Judgment of fractions in Ruby
Implementation of tri-tree in Java
Pitfalls of WebTarget.queryParam () in JAX-RS
Implementation of HashMap in kotlin
[Java] Get the dates of the past Monday and Sunday in order
Spring validation was important in the order of Form and BindingResult