0

I have a web application that receives user inputs and generates a report based on those inputs, opening it in a new page. This application is deployed on Kubernetes.

The problem is that while everything works fine locally, when I try to submit the form in the cloud (which is configured to hit the endpoint that generates the report), Flask does not prepend the prefix. For example, the expected URL is myhostname.com/myteam/myapp/report, but the actual URL is just myhostname.com/report

Here is part of my K8s ingress

spec:
  rules:
  - host: myhostname.com
    http:
      paths:
      - backend:
          service:
            name: myteam-myapp
            port:
              number: 80
        path: /myteam/myapp/(.*)
        pathType: Prefix

Here's the app routes, including werkzeug implementation

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_host=1)
app.config['APPLICATION_ROOT'] = '/myteam/myapp'

@app.route("/form",  methods=["GET"])
def form():
    return render_template('form_input_template.html')

@app.route("/report", methods=["POST"])
def generate_report():
    # Code that generates html report
    return HTML

I attempt to hit the generate_report endpoint via this code in my form_input_template.html:

<form action="{{ url_for('generate_report') }}" method="post" target="_blank">

I did try to use Flask' Blueprint to add the prefix, but while that does prepend the prefix, Flask would then expect prefix to be duplicated (i.e., it would only work if I do myhostname.com/myteam/myapp/myteam/myapp/report which is not what I want.

I also tried to add _external=True (e.g., <form action="{{ url_for('generate_report', _external=True) }}" method="post" target="_blank"> but that didn't work either.

Any help is appreciated!

0

Browse other questions tagged or ask your own question.