Can a DART application host a web server such as Apache?

My impression is that the DART program cannot be hosted on a web server. Can someone please enlighten me on this?

+5
source share
3 answers

Yes, it can (although this is not its main use case).

From Google Plus, February 28, 2013 :

Finally, I managed to get Dart to work in Apache CGI! I did not find any information about this, so I tried it myself. Here is how I did it (Apache 2.2 and Ubuntu) ...

From news.dartlang.org, May 26, 2012

mod_dart: Dart, Apache! PHP, Perl, Python , Dart - - Apache.

" ", , Dart -, Apache.

"..."

, Dart -, Dart node.js, dart . -, :

main() {
  var server = new HttpServer();

  server.addRequestHandler(
     (req) => true,   // matcher - should this function handle this request?
     (req, res) {     // handler - what should happen when this request matches?
       res.outputStream.write("${req.method}: ${req.path}"); // eg: GET: /foo
       res.outputStream.close();
     });

  server.listen('127.0.0.1', 8080);
+6

2 .

0

Apache CGI Dartlang 2.3:

"dartaotruntime" "/var/www/your-site/cgi-bin"

$ chown apache: apache dartaotruntime

test.cgi

#!/bin/sh

BASE=/var/www/your-site/cgi-bin
$BASE/dartaotruntime $BASE/test.aot

$ chmod 0755 test.cgi

$ chown apache: apache test.cgi

test.dart

import 'dart:io';

void main(List<String> args) {
        Map<String, String> envVars = Platform.environment;
        print("Content-Type: text/html\n");

        String input = "";
        if (envVars['REQUEST_METHOD'] == 'POST') {
                var content_length = int.parse(envVars['CONTENT_LENGTH']);
                while(input.length < content_length) {
                        input += stdin.readLineSync();
                }
        }
    print("""
<html>
<form method="post" action="test.cgi">
Name: <input type="text" name="name" value="" />
Email: <input type="text" name="email" value="" />
<input type="submit" value="Submit" />
</form>
<p><strong>ENV:</strong> {$envVars}</p>
<p><strong>INPUT:</strong> {$input}</p>
</html>""");
}

$ dart2aot test.dart test.aot

$ chown apache: apache test.aot

Launch CGI: https://www.your-site.com/cgi-bin/test.cgi

0
source

All Articles