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