Answer the question
In order to leave comments, you need to log in
How to connect an https domain to flask?
The API works on VPS on Python Flask.
Requests go to the IP address from http:// 123.456.123.456/api/ It is
necessary to put a domain with https instead of IP
. To do this, I wrote a code from examples from Google:
from flask import Flask
from flask import jsonify, make_response, request, abort, redirect
from flask_sslify import SSLify
from flask_cors import CORS
import conf
WEBHOOK_HOST = '123.456.123.456'
WEBHOOK_PORT = 80
WEBHOOK_LISTEN = '0.0.0.0'
DATABASE = conf.database
app = Flask(__name__)
context = ('crt.crt', 'key.key')
sslify = SSLify(app)
CORS(app)
@app.route('/', methods=['GET'])
def get_data():
data = {}
return jsonify(data)
# Start flask server
app.run(host=WEBHOOK_LISTEN,
port=WEBHOOK_PORT,
debug=False,
ssl_context=context)
Answer the question
In order to leave comments, you need to log in
The easiest way is to simply add --certfile crt.crt --keyfile key.key to flask run
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question