Skip to content
This repository has been archived by the owner on Oct 16, 2022. It is now read-only.

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

Open
Carl-CWX opened this issue Jun 2, 2021 · 0 comments

Comments

@Carl-CWX
Copy link

Carl-CWX commented Jun 2, 2021

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('');
      }
    });
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant