Migrating from Google App Engine to Heroku (missing YAML)

前端 未结 2 1641
南笙
南笙 2021-01-07 00:44

Overnight hack, trying to create an environment where GAE code (using Python libs/packages) could be easily ported over to Heroku with minimal editing.

EDIT<

相关标签:
2条回答
  • 2021-01-07 00:53

    It sounds to me like the problem you're trying to solve is serving static pages using Django on Heroku.

    collectstatic seems to be the right answer for this: web: python my_django_app/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT my_django_app/settings.py

    http://matthewphiong.com/managing-django-static-files-on-heroku

    0 讨论(0)
  • 2021-01-07 01:07

    On heroku platform, with high volume apps you're supposed to use amazon s3 for static asset storage: https://devcenter.heroku.com/articles/s3

    For development purposes I created a simple "catch all" handler (it should be the last handler in the list) that serves static files that end with certain suffixes from the project directory. Adding this is quite simple. But remember, it's not very effective, and it's a waste of the web dynos resources.

    import webapp2
    import re
    import os
    
    class FileHandler(webapp2.RequestHandler):
      def get(self,path):
    
        if re.search('html$',path):
          self.response.headers['Content-Type'] = 'text/html' 
        elif re.search('css$',path):
          self.response.headers['Content-Type'] = 'text/css' 
        elif re.search('js$',path):
          self.response.headers['Content-Type'] = 'application/javascript' 
        elif re.search('gif$',path):
          self.response.headers['Content-Type'] = 'image/gif' 
        elif re.search('png$',path):
          self.response.headers['Content-Type'] = 'image/png' 
        else:
          self.abort(403)
        try:
          f=open("./"+path,'r')
        except IOError:
          self.abort(404)
        self.response.write(f.read())
        f.close
    
    app = webapp2.WSGIApplication([
        (r'/(.*)', FileHandler),
    ], debug=True)
    
    def main():
        from paste import httpserver
        port = int(os.environ.get('PORT', 8080))
        httpserver.serve(app, host='0.0.0.0', port=port)
    
    if __name__ == '__main__':
        main()
    
    0 讨论(0)
提交回复
热议问题