burktelefon
burktelefon

Reputation: 1018

Server-side app unable to locate dart.js

I'm trying make an application with both client and server-side code. The server code is in a directory called 'bin', the html- with corresponding css- and dart-files are in a directory called 'web'. The latter are returned correctly (with the help of VirtualDirectory), but when it comes to files in 'packages' they are not found. E.g. /packages/browser/dart.js

I have tried on a windows-, and (ubuntu) linux-machine. I've tried starting from the editor both in checked-, and unchecked-mode. I've run pub build with root permission, and also started the app from command line with 'sudo'. I can see the browser-directory in '.pub-cache', but I cant open it.

What am I missing here?

Upvotes: 1

Views: 116

Answers (1)

Xavier
Xavier

Reputation: 4005

bin/server.dart:

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

main() {
  HttpServer.bind(InternetAddress.ANY_IP_V4, 80).then((server) {
    new VirtualDirectory('../web')
        ..jailRoot = false
        ..serve(server);
  });
}

Now you can access dart.js with

http://localhost/packages/browser/dart.js

The trick is to set jailRoot = false to allow the server to serve file from outside the root directory.

Upvotes: 1

Related Questions