lzjun567 / flask-siwadoc

flask-siwadoc is a flask data validator and openapi document generator automaticly
MIT License
55 stars 14 forks source link

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

Open DAAworld opened 1 year ago

DAAworld commented 1 year ago

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 commented 1 year ago

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

DAAworld commented 1 year ago

经过测试,问题出现在 这行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)

lzjun567 commented 1 year ago

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

DAAworld commented 1 year ago

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

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

verydemo commented 11 months ago

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

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

verydemo commented 11 months ago

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

verydemo commented 11 months ago

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