OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #import('../../frog/lib/node/node.dart'); | 5 #import('../../frog/lib/node/node.dart'); |
6 #import('../../frog/file_system_node.dart'); | 6 #import('../../frog/file_system_node.dart'); |
7 #import('../../frog/lang.dart'); | 7 #import('../../frog/lang.dart'); |
8 | 8 |
9 String compileDart(String basename, String filename) { | 9 String compileDart(String basename, String filename) { |
10 final basedir = path.dirname(basename); | 10 final basedir = path.dirname(basename); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 final dartdir = path.dirname(homedir); | 70 final dartdir = path.dirname(homedir); |
71 print('running with dart root at ${dartdir}'); | 71 print('running with dart root at ${dartdir}'); |
72 | 72 |
73 initializeCompiler(homedir); | 73 initializeCompiler(homedir); |
74 | 74 |
75 http.createServer((ServerRequest req, ServerResponse res) { | 75 http.createServer((ServerRequest req, ServerResponse res) { |
76 var filename; | 76 var filename; |
77 if (req.url.endsWith('.html')) { | 77 if (req.url.endsWith('.html')) { |
78 res.setHeader('Content-Type', 'text/html'); | 78 res.setHeader('Content-Type', 'text/html'); |
79 } else if (req.url.endsWith('.css')) { | 79 } else if (req.url.endsWith('.css')) { |
80 res.setHeader('Content-Type', 'text/css'); | 80 res.setHeader('Content-Type', 'text/css'); |
| 81 } else if (req.url.endsWith('.svg')) { |
| 82 res.setHeader('Content-Type', 'image/svg+xml'); |
81 } else { | 83 } else { |
82 res.setHeader('Content-Type', 'text/plain'); | 84 res.setHeader('Content-Type', 'text/plain'); |
83 } | 85 } |
84 | 86 |
85 filename = '$dartdir/${req.url}'; | 87 filename = '$dartdir/${req.url}'; |
86 | 88 |
87 if (path.existsSync(filename)) { | 89 if (path.existsSync(filename)) { |
88 var stat = fs.statSync(filename); | 90 var stat = fs.statSync(filename); |
89 if (stat.isFile()) { | 91 if (stat.isFile()) { |
90 res.statusCode = 200; | 92 res.statusCode = 200; |
91 String data; | 93 String data; |
92 if (filename.endsWith('.html')) { | 94 if (filename.endsWith('.html')) { |
93 res.end(frogify(filename)); | 95 res.end(frogify(filename)); |
94 } else { | 96 } else { |
95 res.end(fs.readFileSync(filename, 'utf8')); | 97 res.end(fs.readFileSync(filename, 'utf8')); |
96 } | 98 } |
97 return; | 99 return; |
98 } else { | 100 } else { |
99 res.setHeader('Content-Type', 'text/html'); | 101 res.setHeader('Content-Type', 'text/html'); |
100 res.end(dirToHtml(req.url, filename)); | 102 res.end(dirToHtml(req.url, filename)); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 | 106 |
105 res.statusCode = 404; | 107 res.statusCode = 404; |
106 res.end(''); | 108 res.end(''); |
107 }).listen(1337, "localhost"); | 109 }).listen(1337, "localhost"); |
108 print('Server running at http://localhost:1337/'); | 110 print('Server running at http://localhost:1337/'); |
109 } | 111 } |
OLD | NEW |