【发布时间】:2020-11-06 11:05:44
【问题描述】:
我的应用程序在本地运行(在终端中本地运行 Heroku 时),路线正确。但是,当我移动到 Heroku 服务器时,应用程序构建得很好,但是当我进入应用程序时只显示 404 错误。 Heroku.logs 对于我进入的任何页面都会返回类似的内容。
2020-07-16T17:24:44.233685+00:00 heroku[router]: at=info method=GET path="/" host=advancedmatchedbetting.herokuapp.com request_id=315ee036-cb58-4493-9b46-c2a25337070e fwd="176.250.1.224" dyno=web.1 connect=1ms service=3ms status=404 bytes=400 protocol=https
我将尽可能少的代码来保持它的简洁,如果还有什么对你有用的,那么请告诉我,我也写出来。 git commit/push/add 都是最新的。
过程文件
web: cd api && export APP_SETTINGS=config.cfg && gunicorn wsgi:app --log-file -
wsgi.py
from application.__init__ import create_app
app = create_app()
if __name__ == "__main__":
app.run()
初始化.py
db = SQLAlchemy()
def create_app():
app = Flask(__name__, static_folder='/Users/ianholdroyd/Documents/GitHub/advancedmatchedbetting_react/build', static_url_path='/')
db.init_app(app)
app.config.from_envvar('APP_SETTINGS')
with app.app_context():
from . import routes
db.create_all()
return app
routes.py
@app.route('/')
def index():
return app.send_static_file('index.html')
@app.route('/api/signup', methods=['POST'])
def signup():
data = request.get_json()
new_user = newsletter(
first_name=data['firstName'],
last_name=data['lastName'],
email= data['email'],
created=dt.now()
)
db.session.add(new_user) # Adds new User record to database
db.session.commit()
return("")
config.cfg
SECRET_KEY = ****
SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG = True
SQLALCHEMY_DATABASE_URI = 'sqlite:///static/site.db'
app.js
function App() {
return (
<Router>
<Switch>
<Route exact path="/" component={homepage} />
<Route exact path = "/404" component={NotFoundPage} />
<Route exact path="/calculator/" component={Calculator} />
<Route exact path="/blogpost/:id" component={blogpostpage} />
<Route exact path="/signup" component={signuppage} />
<Redirect to="/404"/>
</Switch>
</Router>
);
}
export default App;
【问题讨论】:
-
快速更新可能会有所帮助:如果我尝试导航到不是主页的页面,例如0.0.0.0:5000/calculator,我会在本地收到相同的 404 错误,但是如果我这样做,此页面会正常出现首先打开主页,然后从那里导航到计算器页面。
-
我认为这可能与进入反应应用程序需要应用程序路由'/'有关,但是我不确定为什么我什至无法访问此应用程序从 Heroku 页面?
标签: python reactjs flask heroku