Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: lib/src/server/server.dart

Issue 1266483003: format with dart_style 0.2.0-rc.3 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/server/dependency_graph.dart ('k') | lib/src/summary.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Development server that compiles Dart to JS on the fly. 5 /// Development server that compiles Dart to JS on the fly.
6 library dev_compiler.src.server; 6 library dev_compiler.src.server;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 var handler = const shelf.Pipeline() 254 var handler = const shelf.Pipeline()
255 .addMiddleware(rebuildAndCache) 255 .addMiddleware(rebuildAndCache)
256 .addHandler(shelf_static.createStaticHandler(outDir, 256 .addHandler(shelf_static.createStaticHandler(outDir,
257 defaultDocument: _entryPath)); 257 defaultDocument: _entryPath));
258 await shelf.serve(handler, host, port); 258 await shelf.serve(handler, host, port);
259 print('Serving $_entryPath at http://$host:$port/'); 259 print('Serving $_entryPath at http://$host:$port/');
260 compiler.run(); 260 compiler.run();
261 } 261 }
262 262
263 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) { 263 shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) {
264 print('requested $GREEN_COLOR${request.url}$NO_COLOR'); 264 print('requested $GREEN_COLOR${request.url}$NO_COLOR');
265 // Trigger recompile only when requesting the HTML page. 265 // Trigger recompile only when requesting the HTML page.
266 var segments = request.url.pathSegments; 266 var segments = request.url.pathSegments;
267 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath; 267 bool isEntryPage = segments.length == 0 || segments[0] == _entryPath;
268 if (isEntryPage) compiler._runAgain(); 268 if (isEntryPage) compiler._runAgain();
269 269
270 // To help browsers cache resources that don't change, we serve these 270 // To help browsers cache resources that don't change, we serve these
271 // resources by adding a query parameter containing their hash: 271 // resources by adding a query parameter containing their hash:
272 // /{path-to-file.js}?____cached={hash} 272 // /{path-to-file.js}?____cached={hash}
273 var hash = request.url.queryParameters['____cached']; 273 var hash = request.url.queryParameters['____cached'];
274 var response = handler(request); 274 var response = handler(request);
275 var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache'; 275 var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache';
276 var headers = {'cache-control': policy}; 276 var headers = {'cache-control': policy};
277 if (hash != null) { 277 if (hash != null) {
278 // Note: the cache-control header should be enough, but this doesn't hurt 278 // Note: the cache-control header should be enough, but this doesn't
279 // and can help renew the policy after it expires. 279 // hurt and can help renew the policy after it expires.
280 headers['ETag'] = hash; 280 headers['ETag'] = hash;
281 } 281 }
282 return response.change(headers: headers); 282 return response.change(headers: headers);
283 }; 283 };
284 } 284 }
285 285
286 UriResolver _createImplicitEntryResolver(String entryPath) { 286 UriResolver _createImplicitEntryResolver(String entryPath) {
287 var entry = path.absolute(SourceResolverOptions.implicitHtmlFile); 287 var entry = path.absolute(SourceResolverOptions.implicitHtmlFile);
288 var src = path.absolute(entryPath); 288 var src = path.absolute(entryPath);
289 var provider = new MemoryResourceProvider(); 289 var provider = new MemoryResourceProvider();
290 provider.newFile( 290 provider.newFile(
291 entry, '<body><script type="application/dart" src="$src"></script>'); 291 entry, '<body><script type="application/dart" src="$src"></script>');
292 return new _ExistingSourceUriResolver(new ResourceUriResolver(provider)); 292 return new _ExistingSourceUriResolver(new ResourceUriResolver(provider));
293 } 293 }
294 294
295 /// A UriResolver that continues to the next one if it fails to find an existing 295 /// A UriResolver that continues to the next one if it fails to find an existing
296 /// source file. This is unlike normal URI resolvers, that always return 296 /// source file. This is unlike normal URI resolvers, that always return
297 /// something, even if it is a non-existing file. 297 /// something, even if it is a non-existing file.
298 class _ExistingSourceUriResolver implements UriResolver { 298 class _ExistingSourceUriResolver implements UriResolver {
299 final UriResolver resolver; 299 final UriResolver resolver;
300 _ExistingSourceUriResolver(this.resolver); 300 _ExistingSourceUriResolver(this.resolver);
301 301
302 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 302 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
303 var src = resolver.resolveAbsolute(uri, actualUri); 303 var src = resolver.resolveAbsolute(uri, actualUri);
304 return src.exists() ? src : null; 304 return src.exists() ? src : null;
305 } 305 }
306
306 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source); 307 Uri restoreAbsolute(Source source) => resolver.restoreAbsolute(source);
307 } 308 }
308 309
309 final _log = new Logger('dev_compiler.src.server'); 310 final _log = new Logger('dev_compiler.src.server');
310 final _earlyErrorResult = new CheckerResults(const [], null, true); 311 final _earlyErrorResult = new CheckerResults(const [], null, true);
OLDNEW
« no previous file with comments | « lib/src/server/dependency_graph.dart ('k') | lib/src/summary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698