I am now migrating my small Google App Engine app to Heroku platform. I don't actually use Bigtable, and webapp2
reduces my migration costs a lot.
Now I'm stuck on handling the static files.
Is there any good practices? If so, lead me there please.
Thanks in advance.
EDIT
Well, I'm now using paste
for my WSGI server. And paste.StaticURLParser()
should be what I need to implement static file handler. However I have no idea how to integrate it with webapp2.WSGIApplication()
. Could anyone help me?
Maybe I need to override webapp2.RequestHandler
class to load paste.StaticURLParser()
properly;
import os
import webapp2
from paste import httpserver
class StaticFileHandler(webapp2.RequestHandler):
u"""Static file handler"""
def __init__(self):
# I guess I need to override something here to load
# `paste.StaticURLParser()` properly.
pass
app = webapp2.WSGIApplication([(r'/static', StaticFileHandler)], debug=True)
def main():
port = int(os.environ.get('PORT', 5000))
httpserver.serve(app, host='0.0.0.0', port=port)
if __name__ == '__main__':
main()
Any helps would be appreciated!
Below is how I got this working.
I'm guessing that relying on a cascade app isn't the most efficient option, but it works well enough for my needs.
Consider me late to the game, but I actually like DirectoryApp a little better. It handles things a bit more like AppEngine. I can create a "static" directory in my src directory, and then I can reference those in my HTML (or whatever) like this: http:..localhost:8080/static/js/jquery.js
this makes your code more friendly to deploy since you can use nginx to serve your static media in production.