Repository navigation
Description
Problem to Solve
When configuring routes on Serverpod's WebServer, there's currently no way to specify a fallback handler for requests that don't match any defined routes. Say fx. you want to register a specific route /assets/x/y/z and pass all other paths to a SPA.
In Relic you can achieve this with:
final handler = const Pipeline()
.addMiddleware(routeWith(router))
.addHandler(fallbackHandler); // Handles unmatched requestsbut this is not exposed in Serverpod, and cannot easily be exposed as it require the fallbackHandler to be known when building the pipeline, which currently happens to early.
Also it uses the soon-to-be deprecated Pipeline class.
Proposal
Add a Router.fallback property that allows developers to specify a fallback handler for requests that don't match any routes in the router, and can be set late.
Alternatives
-
Implement backtracking so the router tries other routes if no match is found. However, this sacrifices the current performance guarantees. It also makes routing dependent on the order routes are added, which is annoying if/when composition is spread across multiple files.
-
Workaround with manual route configuration, ie. define explicit routes for all paths that need handling:
pod.webServer.addRoute(
AppConfigRoute(serverConfig: pod.config.apiServer),
'/assets/packages/assets/json/config.json',
);
pod.webServer.addRoute(
RouteStaticDirectory(serverDirectory: 'app/assets'),
'/assets/**',
);
pod.webServer.addRoute(
RouteSinglePageApp(serverDirectory: 'app', basePath: '/'),
'/**',
);This works but is convoluted and error-prone, requiring developers to manually manage all path hierarchies.
- Delay pipeline construction in Serverpod.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 🚀
Activity