I am trying to forward my flask api to mydomain.example
with the end point being api.mydomain.example
For example, my method ping
would have a end point api.mydomain.example/v1/server/ping
.
However, what I get is xx.xxx.xxx.xx:5005/v1/server/ping
as endpoint.
Looking in other questions here in SO I found suggestions to modify app.config['SERVER_NAME']
or to add subdomain
to route
decorator. But nothing works. (I get a 404 error when I do any of these modifications).
Here is a minimal working example:
from flask import Flask, Blueprint
from flask_restplus import Resource, Api
app = Flask(__name__)
api = Api(app, version='1.0',
title='My API',
description='An API')
blueprint = Blueprint('api', __name__, url_prefix='/v1')
api.init_app(blueprint)
app.register_blueprint(blueprint)
#app.config['SERVER_NAME'] = 'mydomain.example:5005'
#app.url_map.default_subdomain = "test"
server = api.namespace("server",
description='Server API')
@server.route("/ping") #, subdomain="test")
class Ping(Resource):
def get(self):
"""
Check if Server is still alive
"""
return {"reply":"PONG"}
if __name__ == '__main__':
app.config["SWAGGER_UI_DOC_EXPANSION"] = "list"
app.run(port=5005, host= '0.0.0.0', debug=True)
I went to my domain admin page (name.com
) and added url forward.
In that case, mydomain.info
goes to swagger admin page, but mydomain.example/v1/server/ping
also goes to swagger admin page.
But still, I get xx.xxx.xxx.xx:5005 in the Request URL section.
How do I make it work with the subdomain name?