Skip to content
Permalink
Browse files

feature: No need for packages-folder anymore

  • Loading branch information...
MikeMitterer committed Dec 6, 2016
1 parent 25cba5d commit 39adc76de0b77e376b17441abae27b0afb5e470c
Showing with 19 additions and 4 deletions.
  1. +19 −2 lib/src/Application.dart
  2. +0 −2 samples/simple/web/main.dart
@@ -124,12 +124,29 @@ class Application {
;
virtDir.directoryHandler = _directoryHandler;

final Packages packages = new Packages();

runZoned(() {
HttpServer.bind(ip, int.parse(port)).then( (final HttpServer server) {
_logger.info('Server running on port: $port, $MY_HTTP_ROOT_PATH');
server.listen( (final HttpRequest request) {
_logger.info("${request.connectionInfo.remoteAddress.address}:${request.connectionInfo.localPort} - ${request.method} ${request.uri}");
virtDir.serveRequest(request);
if(request.uri.path.startsWith("/packages")) {
final List<String> parts = request.uri.path.split(new RegExp(r"(?:/|\\)"));
final String path = parts.sublist(3).join("/");
final String packageName = parts[2];

final Package package = packages.resolvePackageUri(
Uri.parse("package:${packageName}")
);
final Uri newUri = Uri.parse("${package.lib.path}/$path");

_logger.info("${request.connectionInfo.remoteAddress.address}:${request.connectionInfo.localPort} - ${request.method} [Rewritten] ${newUri}");
virtDir.serveFile(new File("${package.lib.path}/$path"),request);

} else {
_logger.info("${request.connectionInfo.remoteAddress.address}:${request.connectionInfo.localPort} - ${request.method} ${request.uri}");
virtDir.serveRequest(request);
}
});
});
},
@@ -1,5 +1,3 @@
import 'dart:html' as html;

import 'package:logging/logging.dart';
import 'package:console_log_handler/console_log_handler.dart';

0 comments on commit 39adc76

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.