Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for serving static files

  • Loading branch information...
commit 03300d7f6f5ac2b914c868c0985078646cf40866 1 parent 01bb1c4
@lvivski authored
View
8 bin/run.dart
@@ -2,8 +2,14 @@
final DART_PATH = '/Applications/Dart/dart-sdk/';
+startServerProcess() {
+ var serverProcess = Process.start("$DART_PATH/bin/dart", ["app.dart"]);
+ var stdoutStream = new StringInputStream(serverProcess.stdout);
+ stdoutStream.onLine = () => print(stdoutStream.readLine());
+}
+
void main() {
Process.run("$DART_PATH/bin/pub", ["install"])
.chain((_) => Process.run("$DART_PATH/bin/dart", ["compile.dart"]))
- .then((_) => Process.run("$DART_PATH/bin/dart", ["app.dart"]));
+ .then((_) => startServerProcess());
}
View
4 lib/server.dart
@@ -6,6 +6,7 @@
class Server {
HttpServer _server;
+ String publicDir = 'public';
Server() : _server = new HttpServer();
@@ -15,8 +16,7 @@ class Server {
void listen(host, port) {
_server.defaultRequestHandler = (HttpRequest req, HttpResponse res) {
- new Response(res).status(404).send('Not found!');
- return;
+ new Response(res).sendFile(publicDir + req.path);
};
_server.listen(host, port);
}
View
3  public/stylesheets/main.css
@@ -0,0 +1,3 @@
+h1 {
+ color: #789;
+}
View
6 views/index.haml
@@ -2,5 +2,7 @@
%html
%head
%title= title
- %body.one.two.three
- %h1 Start
+ %link{ rel: "stylesheet", href: "/stylesheets/main.css", type: "text/css"}
+ %body
+ %h1= title
+ %p is awesome
View
48 views/views.dart
@@ -1,48 +0,0 @@
-#library('view');
-#import('package:hart/lib/utils.dart');
-
-class IndexView extends View {
- Map locals;
-
- IndexView(this.locals);
-
- noSuchMethod(String name, List args) {
- if (locals === null) {
- locals = {};
- }
- if (name.length > 4) {
- String prefix = name.substring(0, 4);
- String key = name.substring(4);
- if (prefix == "get:") {
- return locals[key];
- } else if (prefix == "set:") {
- locals[key] = args[0];
- }
- }
- }
-
- get () {
- return '''
-<!DOCTYPE html>\n<html>\n<head>\n<title>${escape(title)}</title></head>\n<body${attrs({ 'class': 'one two three' })}>\n<h1>Start</h1></body></html>
- ''';
- }
-}
-
-class View {
- Map _views;
-
- render(name, params) {
- return _views[name](params).get();
- }
-
- register(name, handler) {
- if (_views == null) {
- _views = {};
- }
- _views[name] = handler;
- }
-
- View() {
- register('index', (params) => new IndexView(params));
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.