Skip to content

Instantly share code, notes, and snippets.

@marc-hughes
Created January 3, 2014 16:21
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 marc-hughes/8240765 to your computer and use it in GitHub Desktop.
Save marc-hughes/8240765 to your computer and use it in GitHub Desktop.
Read in a JS variable called STATIC_URL and use that for static files loaded in an angular.dart application
import 'package:angular/angular.dart';
import 'package:js/js.dart' as js;
class CDNRewriter implements UrlRewriter {
String staticUrl;
CDNRewriter() {
var context = js.context;
staticUrl = js.context.STATIC_URL;
}
String call(String url) {
if (url.startsWith('/static/')) {
return _rewriteCdnUrl(url);
}
return url;
}
String _rewriteCdnUrl(String url) {
return url.replaceFirst(new RegExp(r'/static/'), staticUrl);
}
}
...
type(UrlRewriter, implementedBy: CDNRewriter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment