dart-archive / shelf_static

archived repo
https://github.com/dart-lang/shelf/tree/master/pkgs/shelf_static
BSD 3-Clause "New" or "Revised" License
24 stars 24 forks source link

'Not Found' Response for a file that is present when using createFileHandler #57

Open Carl-CWX opened 3 years ago

Carl-CWX commented 3 years ago

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('');
      }
    });