Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zombie SharedDataMiddleware on Python Heroku

I'm setting up a Flask app on Heroku. Everything is working fine until I added static files. I'm using this:

from werkzeug import SharedDataMiddleware
app = Flask(__name__)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/static': os.path.join(os.path.dirname(__file__), 'static') })

The first time I deploy the app, the appropriate files in the ./static will be available at herokuapp.com/static. But after that initial deploy, the files never change on Heroku. If I change the last line to:

app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/assets': os.path.join(os.path.dirname(__file__), 'static') })

a new URL for the static files, herokuapp.com/assets, then I can see the updated files.

It seems like a mirror of the files gets stuck in the system. I've changed it four times and can access all of the URLs still.

like image 783
nathancahill Avatar asked Jul 17 '12 03:07

nathancahill


1 Answers

SharedDataMiddleware defaults to sending Cache-Control and Expires HTTP headers, which means that your web browser may not even send a request to the server and just use the old files from cache. Try disabling the cache:

app.wsgi_app = SharedDataMiddleware(
    app.wsgi_app,
    {'/static': os.path.join(os.path.dirname(__file__), 'static')},
    cache=False)

Flask does the same with static files. To disable it there:

app.config['SEND_FILE_MAX_AGE_DEFAULT'] = None
like image 89
Simon Sapin Avatar answered Oct 24 '22 00:10

Simon Sapin