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

Side by Side Diff: lib/shelf_packages_handler.dart

Issue 2171743003: Add the package implementation. (Closed) Base URL: git@github.com:dart-lang/shelf_packages_handler.git@master
Patch Set: Code review changes Created 4 years, 5 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 | « codereview.settings ('k') | lib/src/async_handler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 library shelf_packages_handler;
6
7 import 'package:shelf/shelf.dart';
8 import 'package:shelf_static/shelf_static.dart';
9 import 'package:package_resolver/package_resolver.dart';
10 import 'package:path/path.dart' as p;
11
12 import 'src/async_handler.dart';
13 import 'src/dir_handler.dart';
14 import 'src/package_config_handler.dart';
15
16 /// A handler that serves the contents of a virtual packages directory.
17 ///
18 /// This effectively serves `package:${request.url}`. It locates packages using
19 /// the package resolution logic defined by [resolver]. If [resolver] isn't
20 /// passed, it defaults to the current isolate's package resolution logic.
21 ///
22 /// This can only serve assets from `file:` URIs.
23 Handler packagesHandler({PackageResolver resolver}) {
24 resolver ??= PackageResolver.current;
25 return new AsyncHandler(resolver.packageRoot.then((packageRoot) {
26 if (packageRoot != null) {
27 return createStaticHandler(p.fromUri(packageRoot),
28 serveFilesOutsidePath: true);
29 } else {
30 return new PackageConfigHandler(resolver);
31 }
32 }));
33 }
34
35 /// A handler that serves virtual `packages/` directories wherever they're
36 /// requested.
37 ///
38 /// This serves the same assets as [packagesHandler] for every URL that contains
39 /// `/packages/`. Otherwise, it returns 404s for all requests.
40 ///
41 /// This is useful for ensuring that `package:` imports work for all entrypoints
42 /// in Dartium.
43 Handler packagesDirHandler({PackageResolver resolver}) =>
44 new DirHandler("packages", packagesHandler(resolver: resolver));
OLDNEW
« no previous file with comments | « codereview.settings ('k') | lib/src/async_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698