flask-siwadoc icon indicating copy to clipboard operation
flask-siwadoc copied to clipboard

我用nginx配置了一个二级路径,/docs路径就没有办法访问了

Open DAAworld opened this issue 1 year ago • 7 comments

worker_processes 1;

events { worker_connections 1024; }

http { server { listen 80; server_name tttt;

    location /eng/ {
        proxy_pass http://localhost:8800/;
    }
}

} nginx路径配置如下,访问tttt/eng/docs时会报错, Errors Hide

Fetch errorresponse status is 404 /openapi.json

image

DAAworld avatar Oct 09 '23 11:10 DAAworld

我还配置了app.config["APPLICATION_ROOT"] = "/eng/",其他接口都可以使用,只有/docs接口没有办法用

DAAworld avatar Oct 09 '23 11:10 DAAworld

经过测试,问题出现在 这行return render_template(ui_file, spec_url=self.openapi_url),改成return render_template(ui_file, spec_url=“eng" + self.openapi_url)这样就是可以的 @siwa_bp.route(self.doc_url) def doc_html(): siwa_user = self.app.config.get("SIWA_USER") siwa_pass = self.app.config.get("SIWA_PASSWORD") if siwa_user and siwa_pass: global users users = { siwa_user: generate_password_hash(siwa_pass), } login_info = auth.get_auth() password = auth.get_auth_password(login_info) status = None user = auth.authenticate(login_info, password) if user in (False, None): status = 401 elif not auth.authorize(None, user, auth): status = 403 if status: try: return auth.auth_error_callback(status) except TypeError: return auth.auth_error_callback() ui = request.args.get("ui") or self.ui assert ui in SUPPORTED_UI, f"ui only support with {SUPPORTED_UI}" ui_file = f'{ui}.html' return render_template(ui_file, spec_url=self.openapi_url)

DAAworld avatar Oct 10 '23 02:10 DAAworld

这个 /eng 是你的业务路径吧,不能把业务代码侵入到框架代码中去

lzjun567 avatar Oct 16 '23 02:10 lzjun567

这个 /eng 是你的业务路径吧,不能把业务代码侵入到框架代码中去

是的,那是我的业务路径,不知道有什么方法可以配置?

DAAworld avatar Oct 24 '23 01:10 DAAworld

这个 /eng 是你的业务路径吧,不能把业务代码侵入到框架代码中去

应该默认获取同级路由, 不应该自己去配置

verydemo avatar Dec 05 '23 03:12 verydemo

@lzjun567 大佬,改一下templates, 从js 那边获取当前页面的url

verydemo avatar Dec 05 '23 08:12 verydemo

@lzjun567 大佬,改一下templates, 从js 那边获取当前页面的url

verydemo avatar Dec 05 '23 08:12 verydemo