3

I cannot figure out why Flask-CDN is not building my templates with the Amazon CloudFront url for my static files. Here is my setup:

1) Configure cdn domain and ask Flask-Assets to use cdn:

class AppConfig(BaseConfig):
    DEBUG = False
    FLASK_ASSETS_USE_CDN = True
    CDN_DOMAIN = "mydomain.cloudfront.net"

2) The Flask app with the CDN object:

config_object = AppConfig
app = flask.Flask(config_object.PROJECT_NAME, static_folder='web/static')
app.config.from_object(config_object)

# Bundles are configured here (many of them!) to generate the app.js file

if config_object.DEBUG is False:
    CDN(app)

app.run(host='0.0.0.0')

3) The template that uses the assets:

{% assets "js_app" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}

4) Finally, the html built by the server was:

<script type="text/javascript" src="/static/gen/app.js?40c12882"></script>

I'm wondering why the html doesn't contain my CDN domain, as it should have been generated like this:

<script type="text/javascript" src="http://mydomain.cloudfront.net/static/gen/app.js?40c12882"></script>

Thank you.

Daniel Silva
  • 379
  • 1
  • 11
  • the Flask [config documentation](http://flask.pocoo.org/docs/0.10/config/) passes a string to from_object like `app.config.from_object('configmodule.ProductionConfig')` - could this be relevant? Might be worth printing out app.config to see if it's getting set properly – rosshamish Apr 10 '15 at 15:22
  • You can pass a object too: http://flask.pocoo.org/docs/0.10/api/#flask.Config.from_object I've watched the app.config while debugging, and it's with the correct keys. I've also tried to config directly in the app.config['KEYNAME'] without success :( – Daniel Silva Apr 10 '15 at 16:25
  • 1
    You have set your config's object to `DEBUG = False` but is *Flask's* debug mode also set to `False`? – Sean Vieira Apr 10 '15 at 16:51
  • Yep. I call app.run(host='0.0.0.0'), wich sets debug=False by default, I guess. I´ll edit the question to make it more clear. – Daniel Silva Apr 10 '15 at 17:02

1 Answers1

2

Ok. Found the problem. The latest version of Flask-Assets on pip (0.10) does not contain the CDN feature described on docs for current version, that is 0.10.

Daniel Silva
  • 379
  • 1
  • 11