shelf_static
shelf_static copied to clipboard
'Not Found' Response for a file that is present when using createFileHandler
Handler createFileHandler in static_handler.dart, this line is stopping the file being sent : if (request.url.path != url) return Response.notFound('Not Found');
if removed my code works fine and the file is served.
The path parameter is 'public/css/styles.css' (I've checked Directory.current and the path is correctly relative to it) the request.url.path is 'css/styles.css' url var is reduced to 'styles.css' via basename so then is not equal to request.url.path
Not sure if I'm miss using the function? (I'm new to Dart)
Here is my router function :
router.get('/<file|.*>', (Request req) async {
final assetPath = folderPath + '/' + req.requestedUri.path.substring(1);
if (await io.File(assetPath).exists() == true) {
return await createFileHandler(assetPath)(req);
} else {
return Response.notFound('');
}
});