I'm getting this error on deploying to heroku:
at=error code=H10 desc="App crashed" method=GET path="/" host=deploy-testv1.herokuapp.com
request_id=b36172ff-cb1b-4436-978f-1be34e28a9e3 fwd="123.201.36.104" dyno= connect= service=
status=503 bytes= protocol=https
2021-05-18T11:08:48.938254+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET
path="/favicon.ico" host=deploy-testv1.herokuapp.com request_id=8e63e9a0-c621-47e0-a91d-bad7716ddde5
fwd="123.201.36.104" dyno= connect= service= status=503 bytes= protocol=https
My Procfile
:
web: gunicorn app:app
Here is the app.py
file:
from flask import Flask, send_from_directory
from flask_restful import Api, Resource, reqparse
from flask_cors import CORS
from HelloApiHandler import HelloApiHandler
app = Flask(__name__, static_url_path='', static_folder='../build')
CORS(app) #comment this on deployment
api = Api(app)
@app.route("/", defaults={'path':''})
def serve(path):
return send_from_directory(app.static_folder,'index.html')
api.add_resource(HelloApiHandler, '/flask/hello')
HelloApiHandler.py
file:
from flask_restful import Api, Resource, reqparse
class HelloApiHandler(Resource):
def get(self):
return {
'resultStatus': 'SUCCESS',
'message': "Hello Api Handler"
}
def post(self):
print(self)
parser = reqparse.RequestParser()
parser.add_argument('type', type=str)
parser.add_argument('message', type=str)
args = parser.parse_args()
print(args)
# note, the post req from frontend needs to match the strings here (e.g. 'type and 'message')
request_type = args['type']
request_json = args['message']
# ret_status, ret_msg = ReturnData(request_type, request_json)
# currently just returning the req straight
ret_status = request_type
ret_msg = request_json
if ret_msg:
message = "Your Message Requested: {}".format(ret_msg)
else:
message = "No Msg"
final_ret = {"status": "Success", "message": message}
return final_ret
My App.js
file:
import logo from './logo.svg';
import './App.css';
import React, { useEffect, useState } from 'react';
import axios from 'axios'
function App() {
const [getMessage, setGetMessage] = useState({})
useEffect(()=>{
axios.get('https://deploy-testv1.herokuapp.com/flask/hello').then(response => {
console.log("SUCCESS", response)
setGetMessage(response)
}).catch(error => {
console.log(error)
})
}, [])
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>React + Flask Tutorial</p>
<div>{getMessage.status === 200 ?
<h3>{getMessage.data.message}</h3>
:
<h3>LOADING</h3>}</div>
</header>
</div>
);
}
export default App;
My root folder structure
view:
Inside api folder
I have provided everything that's needed. Please let me know what wrong am I doing? Is there something wrong in my procfile or in app.py/app.js? Or is my file structure incorrect?
Have also added nodejs and python buildpack in heroku.