Router
In the Introduction section of Milkio, you must have experienced the “magic” of router. In Milkio, you hardly need to write router code yourself. Milkio automatically reads files in the /src/apps
directory and generates routes for all your APIs.
Customizing Routing Logic
In most cases, you will only need the routes generated by Milkio. However, there may be some special cases where you need to customize your routes. In such cases, you can edit the /src/router.ts
file. Its content will be similar to the following:
You can edit the content of this method to supplement the routing logic beyond what Milkio generates automatically. You can return an existing API address, and it will be called. If you return false
, a failure message of NOT_FOUND
will be returned.
This method accepts two parameters: path
and fullurl
. path
represents the suffix of the request path (removing the domain and ignored path levels). For performance reasons, if the URL contains parameters, these parameters will not be removed and will still be preserved in path
, for example, foo/bar?hello=world
. fullurl
is the complete URL object, and the ignored path levels will not be removed.