Gregor
Gregor

Reputation: 3027

Run Dart WebApp on Apache Server

I want to server a Dart application on an Apache server. I added the line

application/dart dart

to the mime.type file in the Apache configuration. Still I get the error

Resource interpreted as Script but transferred with MIME type text/plain:    "http://localhost/~d022051/mastermind/web/mm-game.dart".

Another issue is the link to the packages directory. I do not want to have symlinks in the documents directory of the server. Is there a smart way to copy the required packages in the correct version?

Upvotes: 2

Views: 1173

Answers (2)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657268

This message has nothing to do with Apache.

It's a while that I worked with Apache, but as far as I know you don't need specific settings to serve a Dart client app using Apache. They are just like any other static HTML, CSS, JavaScript, or image files.

You get this message because the entry page (index.html) contains a script tag for a Dart script. After you run pub build there are no Dart scripts (yet) in the build output (this will change when Chrome supports Dart and pub build also generates Dart output).

When the browser finds this (currently redundant) Dart script tag it produces this output. When you want to get rid of this message just remove the script tag from the HTML page in your your_app_package/build/web/index.html file.

EDIT

transformers:
- $dart2js:
    'minify': true
    commandLineOptions: ['--output-type=dart']

or

    commandLineOptions: ['--output-type=dart', '--categories=Server']

I haven't tested if this categories argument has an effect in dart2dart too.

EDIT END

EDIT2

There is also the output type dart-multi which creates one output file per input library. See https://code.google.com/p/dart/issues/detail?id=21616#c9 for more details.

EDIT2 END

Upvotes: 3

Gregor
Gregor

Reputation: 3027

Add the following lines to the pubspec.yaml file of your package (thanks to Günter, who pointed this out):

transformers:
- $dart2js:
    'minify': true
    commandLineOptions: ['--output-type=dart']

Then run pub build with the option --mode=debug.

This results in a "runnable" Dart application, containing the dart sources and the needed packages. The build directory can then be copied to a location visible to your web server. When loading the corresponding URL in the Dartium browser the application is started.

Upvotes: 0

Related Questions