Customize routes
Overriding Routes in Nile API
Overview
Nile API allows you to override default API routes to better match your application’s structure. This is done by configuring the routes
object in ServerConfig
and setting a custom routePrefix
.
Default Routes
By default, Nile provides the following API routes, prefixed by ServerConfig.api.routePrefix
(default: /api
):
Customizing Routes
You can override specific routes by passing a routes
object when initializing the Server
instance. The routePrefix
can also be customized to change the default API path structure.
Custom Route Prefix
This sets all default routes under /nile/api
instead of /api
, for example:
SIGNIN
will be/nile/api/auth/signin
ME
will be/nile/api/me
nile
instance is located in the correct file. For example, in this case it would be in /nile/api/[...nile]/route.ts
in NextJS. For more complicated setups, you may need to import nile from multiple locations.Overriding Specific Routes
This changes:
ME
from/api/me
to/profile
TENANT_USERS
from/api/tenants/:tenantId/users
to/custom/tenants/:tenantId/users
Combining Custom Prefix and Routes
app/nile.ts
Now:
SIGNIN
is/login
SIGNOUT
is/logout
- Other routes follow the
/nile/api
prefix unless overridden
app/login/route.ts
app/logout/route.ts
app/nile/api/[...nile]/route.ts
Customizing SignIn Component
If you override the SIGNIN
route, you should also update the fetchUrl
prop in your SigningIn
component:
Now, the fetchUrl
in the SignInForm
component correctly maps to the updated SIGNIN
route (/login
in this case).
Notes
- Only specified routes are overridden – others keep their defaults.
- Placeholders (
:tenantId
,{userId}
) in routes work as expected. - Routes cannot be changed at runtime - they must be set in
ServerConfig
at initialization.
By leveraging route overrides, you can align Nile API endpoints with your application’s needs while maintaining flexibility.
Was this page helpful?