Skip to content

Commit

Permalink
Committing step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
domesticmouse committed Mar 20, 2012
1 parent cec7528 commit 71d8046
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions step-01-webserver/.children
@@ -0,0 +1 @@
step01Webserver.dart
17 changes: 17 additions & 0 deletions step-01-webserver/.project
@@ -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>
30 changes: 30 additions & 0 deletions step-01-webserver/step01Webserver.dart
@@ -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.