Skip to content

Instantly share code, notes, and snippets.

@davenotik
Created October 26, 2015 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davenotik/d970f5a05a586f4b5cf8 to your computer and use it in GitHub Desktop.
Save davenotik/d970f5a05a586f4b5cf8 to your computer and use it in GitHub Desktop.
// Rewrite URLs from relative to absolute so URLs
// like /item/whatever properly load the app.
// See http://goo.gl/Y5ERIY
if (request.uri.path.contains('packages/')) {
var path = request.uri.path.replaceFirst(new RegExp('^.*?packages/'), '');
var file = new File(config['server']['directory'] + '/packages/$path');
virtualDirectory.serveFile(file, request);
} else if (request.uri.path.contains('static/')) {
var path = request.uri.path.replaceFirst(new RegExp('^.*?static/'), '');
var file = new File(config['server']['directory'] + '/static/$path');
virtualDirectory.serveFile(file, request);
// The following will handle either index.html or
// post-build assets like index.html_bootstrap.dart.js etc.
} else if (request.uri.path.contains('index.html')) {
var path = request.uri.path.replaceFirst(new RegExp('^.*?index.html'), '');
var file = new File(config['server']['directory'] + '/index.html$path');
virtualDirectory.serveFile(file, request);
} else if (request.uri.path.contains('index.dart')) {
var path = request.uri.path.replaceFirst(new RegExp('^.*?index.dart'), '');
var file = new File(config['server']['directory'] + '/index.dart$path');
virtualDirectory.serveFile(file, request);
// End of ugly relative/absolute handling.
} else {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment