Skip to content

Commit 731dc06

Browse files
committed
Handle local files better in server mode
We're already serving sources from the original directory (for source maps). This lets us serve other resources as well. Makes it simpler to run angular todo and other apps with xhr'ed data. [email protected] Review URL: https://codereview.chromium.org/1644673002 .
1 parent 0b646eb commit 731dc06

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

pkg/dev_compiler/lib/src/server/server.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,20 @@ class DevServer {
254254
var out = new Directory(outDir);
255255
if (!await out.exists()) await out.create(recursive: true);
256256

257-
var mainHandler =
257+
var generatedHandler =
258258
shelf_static.createStaticHandler(outDir, defaultDocument: _entryPath);
259259
var sourceHandler = shelf_static.createStaticHandler(compiler.inputBaseDir,
260260
serveFilesOutsidePath: true);
261+
// TODO(vsm): Is there a better builtin way to compose these handlers?
261262
var topLevelHandler = (shelf.Request request) {
262263
var path = request.url.path;
263-
if (path.endsWith('.dart')) {
264-
return sourceHandler(request);
265-
} else {
266-
return mainHandler(request);
264+
// Prefer generated code
265+
var response = generatedHandler(request);
266+
if (response.statusCode == 404) {
267+
// Fall back on original sources
268+
response = sourceHandler(request);
267269
}
270+
return response;
268271
};
269272

270273
var handler = const shelf.Pipeline()

pkg/dev_compiler/test/codegen/expect/collection/src/unmodifiable_wrappers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Messages from compiling unmodifiable_wrappers.dart
2-
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/src/unmodifiable_wrappers.dart, line 33, col 7)
2+
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/unmodifiable_wrappers.dart, line 33, col 7)
33
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/src/unmodifiable_wrappers.dart, line 136, col 7)
44
warning: [DOWN_CAST_COMPOSITE] _throw() (dynamic) will need runtime check to cast to type E (package:collection/src/unmodifiable_wrappers.dart, line 88, col 28)
55
warning: [DOWN_CAST_COMPOSITE] _throw() (dynamic) will need runtime check to cast to type E (package:collection/src/unmodifiable_wrappers.dart, line 94, col 21)

pkg/dev_compiler/test/codegen/expect/collection/wrappers.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ severe: [INVALID_METHOD_OVERRIDE] Invalid override. The type of _DelegatingItera
44
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/wrappers.dart, line 117, col 7)
55
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable<dynamic>) → Iterable<dynamic>) is not a subtype of Iterable<E>.expand (<T>((E) → Iterable<T>) → Iterable<T>). (package:collection/wrappers.dart, line 117, col 25)
66
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable<dynamic>) is not a subtype of Iterable<E>.map (<T>((E) → T) → Iterable<T>). (package:collection/wrappers.dart, line 117, col 25)
7-
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/wrappers.dart, line 216, col 7)
7+
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/wrappers.dart, line 216, col 7)
88
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable<dynamic>) → Iterable<dynamic>) is not a subtype of Iterable<E>.expand (<T>((E) → Iterable<T>) → Iterable<T>). (package:collection/wrappers.dart, line 216, col 24)
99
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable<dynamic>) is not a subtype of Iterable<E>.map (<T>((E) → T) → Iterable<T>). (package:collection/wrappers.dart, line 216, col 24)
10-
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/wrappers.dart, line 269, col 7)
10+
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/wrappers.dart, line 269, col 7)
1111
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((E) → Iterable<dynamic>) → Iterable<dynamic>) is not a subtype of Iterable<E>.expand (<T>((E) → Iterable<T>) → Iterable<T>). (package:collection/wrappers.dart, line 269, col 26)
1212
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((E) → dynamic) → Iterable<dynamic>) is not a subtype of Iterable<E>.map (<T>((E) → T) → Iterable<T>). (package:collection/wrappers.dart, line 269, col 26)
1313
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/wrappers.dart, line 367, col 7)
14-
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.expand' and 'Iterable.map' (package:collection/wrappers.dart, line 452, col 7)
14+
severe: [AnalyzerMessage] Missing concrete implementation of 'Iterable.map' and 'Iterable.expand' (package:collection/wrappers.dart, line 452, col 7)
1515
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.expand (((V) → Iterable<dynamic>) → Iterable<dynamic>) is not a subtype of Iterable<V>.expand (<T>((V) → Iterable<T>) → Iterable<T>). (package:collection/wrappers.dart, line 452, col 25)
1616
severe: [INVALID_METHOD_OVERRIDE] Base class introduces an invalid override. The type of _DelegatingIterableBase.map (((V) → dynamic) → Iterable<dynamic>) is not a subtype of Iterable<V>.map (<T>((V) → T) → Iterable<T>). (package:collection/wrappers.dart, line 452, col 25)
1717
warning: [DOWN_CAST_COMPOSITE] _base.fold(initialValue, combine) (dynamic) will need runtime check to cast to type T (package:collection/wrappers.dart, line 49, col 7)

0 commit comments

Comments
 (0)