0

I am sending a Dart file via HttpServer, but whenever I get it, Chrome says:

"Resource interpreted as Script but transferred with MIME type application/dart: "http://localhost:8000/dart/game.dart"."

The line for the client is:

<script type="application/dart" src="dart/game.dart"></script>

And the line to give the file is:

if(new RegExp("/dart/(.*)").hasMatch(uri)){
    new File("static/" + uri.substring(1)).exists().then((bool exists){
      if(!exists) return;
        new File("static/" + uri.substring(1)).readAsString().then((String contents){
          if(uri.substring(uri.length - 2, uri.length) == "js")
            request.response.headers.contentType = new ContentType("application", "javascript", charset: "utf-8");
          else
            request.response.headers.contentType = new ContentType("application", "dart");

          request.response.write(contents);
          request.response.close();
      });
    });
  }

When I go directly to the URL, it gives me my file; and Google Chrome networking says this:

Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/dart/game.dart
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8000
Referer:http://localhost:8000/play
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Response Headersview source
content-type:application/dart
transfer-encoding:chunked
x-content-type-options:nosniff
x-frame-options:SAMEORIGIN
x-xss-protection:1; mode=block

What can I do?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
anonmous
  • 137
  • 2
  • 9
  • Everything's fine. You can ignore it. Dart will automatically inject a script that replaces the .dart version with a .js version if you run the script in a browser that does not support Dart natively! This expects that you use the default "pub build" tool. Otherwise you have to make it sure. This message just says that you use a .dart file with application/dart mime type as a – Robert Dec 06 '14 at 09:18
  • What's the purpose of this code? Currently it doesn't make sense to serve Dart source code directly. If you need this for development purposes you should forward the call to a `pub serve` instance and let it take care of the rest. The Dart initialization code takes care that the browser requests the appropriate source and `pub serve` does the rest. – Günter Zöchbauer Dec 06 '14 at 09:38

0 Answers0