sudo snap install --classic heroku
heroku login
heroku create # in your app folder https://hidden-dusk-28735.herokuapp.com/
git push heroku master
heroku authorizations:create # this gives Client,ID,Description,Scope,Token
- name: Deploy to Heroku
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_TOKEN }}
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
Procfile
in your repo.
web gunicorn --pythonpath src app:app
runtime.txt
python-3.7.6
Basics of app.py
# For GET method
@app.route("/",methods=['GET'])
## GET with args
a = requests.args.get('a',None)
## To test GET
r = requests.get('http://ip:port/',params={'a':a})
dct = json.loads(response.content.decode('utf-8'))
# For POST method
@app.route("/",methods=['POST'])
## POST with args
a = requests.values.get('a',None)
## To test POST
r = requests.post('http://ip:port/',params={'a':a}) # for simple datatype
r = requests.post('http://ip:port/',json={'a':list}) # for image list
dct = json.loads(response.content.decode('utf-8'))
# return
## template
render_template('xx.html',**kwargs)
## json
jsonpify({'output':output,'data':data})
Just want to make a fake api, just like How to use fakestoreapi, some data look like this link https://fakestoreapi.com/products?limit=5.
May encounter this bug: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://hidden-dusk-28735.herokuapp.com/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
Solve by adding this to python
from flask_cors import CORS
app = Flask(__name__)
CORS(app)