fix(api-doc): invalid headers

This commit is contained in:
chenos 2024-01-12 09:14:27 +08:00
parent 1871fdd895
commit 57a2bac72a

View File

@ -12,13 +12,13 @@ const Documentation = () => {
const apiClient = useAPIClient(); const apiClient = useAPIClient();
const { t } = useTranslation(); const { t } = useTranslation();
const swaggerUIRef = useRef(); const swaggerUIRef = useRef();
const { data: urls } = useRequest<{ data: { name: string; url: string }[] }>({ url: 'swagger:getUrls' }); const { data: urls } = useRequest<{ data: { name: string; url: string }[] }>({ url: 'swagger:getUrls' });
const requestInterceptor = (req) => { const requestInterceptor = (req) => {
if (!req.headers['Authorization']) { if (!req.headers['Authorization']) {
const match = location.pathname.match(/^\/apps\/([^/]*)\//); const match = location.pathname.match(/^\/apps\/([^/]*)\//);
// multi apps need to set X-App header if (match?.[1]) {
req.headers['X-App'] = match?.[1] || 'main'; req.headers['X-App'] = match?.[1];
}
req.headers['Authorization'] = `Bearer ${apiClient.auth.getToken()}`; req.headers['Authorization'] = `Bearer ${apiClient.auth.getToken()}`;
} }
return req; return req;