You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add the possibility to specify a regular expression as route
my use case is this simple app that I have a Rest API and in the "/storage/" endpoint I want to serve static files
void_startServer(List args) async {
String address = args[1] asString;
int port = args[2];
final app =Router();
//define other routes of approutes(app);
final staticFileHandler =createStaticHandler('storage');
// today's workaroud
app.all(r'/storage/<file|.*>', (Request rec, String file) {
print('staticFileHandler ${rec.url}');
final pathSegments = [...rec.url.pathSegments]..removeAt(0);
rec.url.replace(pathSegments: pathSegments);
returnstaticFileHandler(rec);
});
final handler =Pipeline()
.addMiddleware(corsHeaders())
.addMiddleware(logRequests())
.addHandler(app);
final server =await io.serve(handler, address, port, shared:true);
server.defaultResponseHeaders.remove('X-Frame-Options', 'SAMEORIGIN');
print('Serving at http://${server.address.host}:${server.port}');
}
import'package:shelf_router/shelf_router.dart';
voidmain() {
final app =Router();
// Define a route using a regular expression
app.all(RegExp(r'^/storage.*'), (Request request) {
// Handle the route logic herereturnResponse.ok('Matched /storage route');
});
// Start the server// ...// Example: Match URLsprint(app.canRoute(Request('GET', '/storage/file.txt'))); // Should print trueprint(app.canRoute(Request('GET', '/storage/images/photo.jpg'))); // Should print trueprint(app.canRoute(Request('GET', '/other-route'))); // Should print false
}
The text was updated successfully, but these errors were encountered:
add the possibility to specify a regular expression as route
my use case is this simple app that I have a Rest API and in the "/storage/" endpoint I want to serve static files
The text was updated successfully, but these errors were encountered: