Created
January 3, 2014 16:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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