【发布时间】:2020-07-19 19:48:51
【问题描述】:
使用 Flask 作为 Web 服务器,使用 Angular 作为我在 /static 目录中的 SPA。我在我的 Flask 应用程序上实现了一个包罗万象的端点,以尝试解决用户在刷新页面时得到404 的问题,但这并没有解决问题。有谁知道如何解决这个问题?
包罗万象的样子:
@application.route('/', defaults={'path': ''})
@application.route('/static/<path:path>')
def main(path):
return render_template('index.html')
如果抛出 404,我还实现了重定向,但这也无济于事:
@application.errorhandler(Exception)
@cross_origin()
def main_404(*args, **kwargs):
logger.info("Routing passed to web application...")
return render_template('index.html')
【问题讨论】:
-
如果你路由到
/static/,你还没有路由到/static/<path:path>。 ;这可能是 catch all 处理程序的问题。 -
这个问题似乎是由于 /static 目录。如果我输入 elasticbeanstalkurl.com/foobar/foo 我的 404 重定向效果很好。但是当用户在页面上并且他们点击刷新时,url 是 elasticbeanstalkurl.com/static/foo 他们得到一个 404。这是因为 beanstalk 试图在 /static 目录中找到一个名为 /foo 的文件(有点像/static/index.html 如何将它们带到应用程序中)。知道如何阻止这种情况吗?
标签: python amazon-web-services flask amazon-elastic-beanstalk single-page-application