Permalink
Browse files

Committing step 1

  • Loading branch information...
1 parent cec7528 commit 71d8046ceea88bbf9e071f05623e31a97dda1cba @domesticmouse committed Mar 20, 2012
Showing with 48 additions and 0 deletions.
  1. +1 −0 step-01-webserver/.children
  2. +17 −0 step-01-webserver/.project
  3. +30 −0 step-01-webserver/step01Webserver.dart
@@ -0,0 +1 @@
+step01Webserver.dart
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>step-01-webserver</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.google.dart.tools.core.dartBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.google.dart.tools.core.dartNature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,30 @@
+#import('dart:io');
+#import('dart:uri');
+
+main() {
+ HttpServer server = new HttpServer();
+
+ server.listen('127.0.0.1', 8080);
+ server.onRequest = helloWorld;
+}
+
+void helloWorld(HttpRequest request, HttpResponse response) {
+ log("Serving request for ${request.path + (request.queryString == null? "" : "?"+request.queryString)}");
+ response.headers['Content-Type'] = 'text/html';
+ response.outputStream.writeString('''
+<html>
+<head>
+ <title>Hello World</title>
+</head>
+<body>
+ <h1>Hello Peeps!</h1>
+ <p>It is currently ${new Date.now()}</p>
+</body>
+</html>
+''');
+ response.outputStream.close();
+}
+
+void log(String data) {
+ print("${new Date.now()}: $data");
+}

0 comments on commit 71d8046

Please sign in to comment.