Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cec7528
commit 71d8046
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
step01Webserver.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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"); | |||
} |