GoogleCloudPlatform / flask-talisman

HTTP security headers for Flask
Apache License 2.0
921 stars 85 forks source link

On using flask-talisman with application factory pattern #71

Open lahdjirayhan opened 3 years ago

lahdjirayhan commented 3 years ago

I tried the following in my app.py:

from flask_talisman import Talisman
from flask_main import create_app

app = create_app()
Talisman(app)

if __name__ == "main":
    app.run()

It still does not work. Any request coming to https:// returns SSL_ERROR_RX_RECORD_TOO_LONG. I've tried both commands to start the app: flask run and python app.py, nothing changes.

Per this issue #66, doing this in create_app won't work.

from flask import Flask
from flask_talisman import Talisman
from flask_main.configuration import Configuration

talisman = Talisman()

def create_app():
    app = Flask(__name__)
    app.config.from_object(Configuration)
    talisman.init_app(app)

Is there any way to make flask-talisman work with application factory pattern?

sbutler44 commented 1 year ago

I'm using an application factory, and it is working well with the code you've used above.