1

I have a site on Google Domains (http://example.com).

But I want it should redirect to https://example.com on flexible app engine environment.

what changes required in app.yaml for flexible app engine environment.

Mu current app.yaml as below:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10
gameon67
  • 3,981
  • 5
  • 35
  • 61
pradeep
  • 23
  • 1
  • 6
  • No changes are required to app.yaml. Follow this documentation: https://cloud.google.com/appengine/docs/flexible/python/securing-custom-domains-with-ssl – John Hanley Feb 21 '19 at 05:06
  • @JohnHanley I have gone through a document I have done this setps currently, my example.com domain working both http and https request. My requirement is should work only on https. All requests should open using https:// not through http:// – pradeep Feb 21 '19 at 05:21
  • You will need to check the protocol in your code and for HTTP redirect the user with a 301 or 307 to HTTPS. Nothing is provided for you by App Engine Flexible. You provide the logic in your code. – John Hanley Feb 21 '19 at 05:52
  • @JohnHanley Can you show me sample application. How we can redirect? – pradeep Feb 21 '19 at 06:14

1 Answers1

1

In order to redirect HTTP to HTTPS using a Flask application in App Engine Flexible Environment you only need to use the small Flask extension called Talisman.

In your requirements.txt you have to add a line containing flask-talisman.

In your main.py you just have to import Talisman and wrap your Flask app with it:

from flask import Flask
from flask_talisman import Talisman

app = Flask(__name__)
Talisman(app)

By default, doing this redirects to HTTPS.

Take into account that Talisman is not an official Google product, experimental or otherwise.

asbovelw
  • 552
  • 2
  • 9