1

I have a simple Dart HTTPServer running which serves requests by virDir.serveRequest(request); which works for the URL 192.168.1.200:8080/index.html but serves a 404 Not Found if I use 192.168.1.200:8080 or 192.168.1.200:8080/. I, probably naively, though that the default was automatic. BTW this is all new to me.

I didn't notice any default settings in HTMLServer, how is this accomplished?

(edit)

I've been able to detect the use using the default and compute the correct file name but don't understand how to deliver it to the browser:

_processRequest(newPath, request) { // new path is index.html
  File file = new File(newPath);
  file.exists().then((found) {
    if(found) {
      file.openRead().pipe(request.response);  // probably dies here
      }
    else {
     _send404(request.response);
    }
   });
}

[edit]

Still unable to serve the index.html file. I've tried using VirtualDirector.serveFile() but can't make it work when I try to handle the default index.html file. I've been attempting to follow an example.

final HTTP_ROOT_PATH = Platform.script.resolve('../web').toFilePath();
final virDir = new VirtualDirectory(HTTP_ROOT_PATH)
  ..jailRoot = false  // process links will work
  ..followLinks = true
  ..allowDirectoryListing = true;

var dir = new Directory(virDir.root);
var indexUri = new Uri.file(dir.path).resolve('/index.html');
virDir.serveFile(new File(indexUri.toFilePath()), request);

When I run this and print indexUri.toFilePath() the output is '/index.html'

My code is in /srv/fireimager/bin and /srv/fireimager/web with the latter the virtual directory root. When I detect that the user has not specified /index.html in the url it doesn't work, there's no error emitted, and the javascript console shows nothing so nothing is served to the browser.

I obviously don't understand how to use VirtualDirectly.serveFiler.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Nate Lockwood
  • 3,325
  • 6
  • 28
  • 34

1 Answers1

0

Your default page or index.html is not assumed by your browser but by the server.

What you will want to do is check to see what your request ends with. In my server, I check to see if it ends with a "/". If it does end with a "/", I open and send my default page.

Also, you will want to make sure you check your request to make sure it's not trying to access areas it it not suppose to. Check for ".." in your path segments. If you have any, you probably want to kill the connection.

ptDave
  • 392
  • 1
  • 2
  • 11