Running a dart on a web server

How to run dart on the server? let's say in localhost or on any web server? Google currently provides a dart editor that runs code in the dartium browser. Also, even if I can run it on the server, will it be visible to others viewing the page in a browser other than dartium?

+8
dart dartium
source share
4 answers

When you create a new “web application” using the Dart editor, it creates a .html file and a .dart file. The html file uses a tag to link to the .dart file, for example:

MyApp.html //contains <script type="application/dart" src="MyApp.dart"></script> MyApp.dart //contains dart app code. 

The editor can also generate a javascript file from a .dart file, for example:

 MyApp.dart.js //contains dart app code converted to JS 

As for the web server, these are just static files that are transferred to the browser.

The html file contains a link to a special JavaScript script that can identify if the browser used has built-in Dart support (i.e. Dartium).

  • If so, then a couple of MyApp.html and MyApp.dart files are used.

  • If the browser does not support Dart initially, a special script dynamically changes the script element to point to the MyApp.dart.js file instead, so that the browser receives a javascript version of your application.

This means that you can copy three files (.html, .dart, .js) to any web server (localhost or otherwise) and just go to the .html file.

For completeness, the “special script” can be viewed here: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js

+9
source share

You can run Dart as a web server:

 import 'dart:io'; main() { HttpServer.bind('127.0.0.1', 8080).then((server) { server.listen((HttpRequest request) { request.response.write('Hello, world'); request.response.close(); }); }); } 

This starts the web server on the local machine using port 8080. It simply returns "Hello, world".

From there, all you have to do is determine your routes, activities, etc.

+11
source share

Dartium is the only Chromium browser with the ability to directly launch the dart in "dart vm". This speeds up the development process. A common way to use the dart in other browsers and on your web server is: compile the dart code into the built-in javascript :)

http://www.dartlang.org/docs/getting-started/sdk/#frog

Frog is a compiler that compiles dart-code in javascript

0
source share

This is how I put Dart in the Google App Engine, that is: Dart running in the browser / client side:

http://ambio-strong.blogspot.no/2012/07/dart-on-google-app-engine.html

-one
source share

All Articles