Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

inserting a pathPrefix with relative paths breaks the web server. #81

Description

@jonataslaw

Hi, this library really makes writing an http server a lot easier. However, when defining a path, it does not work properly.

Code to reproduce:

import 'dart:io';
import 'package:http_server/http_server.dart';

Future main() async {
  var staticFiles = VirtualDirectory('web', pathPrefix: '/app');
  staticFiles.allowDirectoryListing = true;
  staticFiles.directoryHandler = (dir, request) {
    var indexUri = Uri.file(dir.path).resolve('index.html');
    staticFiles.serveFile(File(indexUri.toFilePath()), request); 
  };

  var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8080);
  print('Listening on port 8080');
  await server.forEach(staticFiles.serveRequest); /*4*/
}

Steps to reproduce:

This is the standard example on the dart website.
Insert a pure html file, and it will work.
Insert a file that contains relative paths to other files, and it will display an error.

http://localhost:8080/app

image

Apparently, only the html file will be called correctly, but as it makes another request to the same server, the file will not be found.
It is expected that it will look for the file in the VirtualDirectory path, but this does not happen if a pathPrefix is defined. Removing pathPrefix, everything works fine.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions