如何使用 flask_restplus 为 swagger 设置基数 url?
How to set base url for swagger with flask_restplus?
我正在使用来自 apache 服务器的 flask_restplus
提供一个烧瓶应用程序。我正在使用 ProxyPass
将所有流量转发到某个 url 扩展名的应用程序,就像在 apache .conf
文件中一样:
ProxyPass /some-extension http://127.0.0.1:3000
ProxyPassReverse /some-extension http://127.0.0.1:3000
flask_restplus
api设置如下:
from flask_restplus import Api
api = Api(
title='App Title',
doc='/docs'
)
该应用程序运行正常,除了当我转到 swagger 路由 /some-extension/docs
时,flask 服务器开始在 url base /swaggerui/(而不是所需的 /some-extension/swaggerui
),因此 swagger UI 无法加载。
有没有办法配置 flask_restplus
(或其他方式)以便 swagger 得到服务 /some-extension/swaggerui/
(而不是根 url)?
好的,经过一些摆弄后到达那里。您需要将流量代理到扩展并设置带有蓝图的烧瓶,以便整个应用程序也从该扩展运行。所以在你的 apache 配置中是这样的:
ProxyPass /some-extension http://127.0.0.1:3000/some-extension
ProxyPassReverse /some-extension http://127.0.0.1:3000/some-extension
...并且您必须在您的 apache 配置中像这样 ProxyPass 扩展名 /swaggerui:
ProxyPass /swaggerui http://127.0.0.1:3000/swaggerui
ProxyPassReverse /swaggerui http://127.0.0.1:3000/swaggerui
...然后在您的 flask_restplus
设置中使用此模式(来自 official guide):
from flask import Flask, Blueprint
from flask_restplus import Api
app = Flask(__name__)
blueprint = Blueprint('api', __name__, url_prefix='/some-extension')
api = Api(blueprint, doc='/docs/')
app.register_blueprint(blueprint)
我正在使用来自 apache 服务器的 flask_restplus
提供一个烧瓶应用程序。我正在使用 ProxyPass
将所有流量转发到某个 url 扩展名的应用程序,就像在 apache .conf
文件中一样:
ProxyPass /some-extension http://127.0.0.1:3000
ProxyPassReverse /some-extension http://127.0.0.1:3000
flask_restplus
api设置如下:
from flask_restplus import Api
api = Api(
title='App Title',
doc='/docs'
)
该应用程序运行正常,除了当我转到 swagger 路由 /some-extension/docs
时,flask 服务器开始在 url base /swaggerui/(而不是所需的 /some-extension/swaggerui
),因此 swagger UI 无法加载。
有没有办法配置 flask_restplus
(或其他方式)以便 swagger 得到服务 /some-extension/swaggerui/
(而不是根 url)?
好的,经过一些摆弄后到达那里。您需要将流量代理到扩展并设置带有蓝图的烧瓶,以便整个应用程序也从该扩展运行。所以在你的 apache 配置中是这样的:
ProxyPass /some-extension http://127.0.0.1:3000/some-extension
ProxyPassReverse /some-extension http://127.0.0.1:3000/some-extension
...并且您必须在您的 apache 配置中像这样 ProxyPass 扩展名 /swaggerui:
ProxyPass /swaggerui http://127.0.0.1:3000/swaggerui
ProxyPassReverse /swaggerui http://127.0.0.1:3000/swaggerui
...然后在您的 flask_restplus
设置中使用此模式(来自 official guide):
from flask import Flask, Blueprint
from flask_restplus import Api
app = Flask(__name__)
blueprint = Blueprint('api', __name__, url_prefix='/some-extension')
api = Api(blueprint, doc='/docs/')
app.register_blueprint(blueprint)