mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 08:02:04 +10:00
* Share - WIP * - public attachment links - WIP * WIP * WIP * Share - WIP * WIP * WIP * include userRole in space object * WIP * Server render shared page meta tags * disable user select * Close Navbar on outside click on mobile * update shared page spaceId * WIP * fix * close sidebar on click * close sidebar * defaults * update copy * Store share key in lowercase * refactor page breadcrumbs * Change copy * add link ref * open link button * add meta og:title * add twitter tags * WIP * make shares/info endpoint public * fix * * add /p/ segment to share urls * minore fixes * change mobile breadcrumb icon
79 lines
2.0 KiB
TypeScript
79 lines
2.0 KiB
TypeScript
import axios, { AxiosInstance } from "axios";
|
|
import APP_ROUTE from "@/lib/app-route.ts";
|
|
import { isCloud } from "@/lib/config.ts";
|
|
|
|
const api: AxiosInstance = axios.create({
|
|
baseURL: "/api",
|
|
withCredentials: true,
|
|
});
|
|
|
|
api.interceptors.response.use(
|
|
(response) => {
|
|
// we need the response headers for these endpoints
|
|
const exemptEndpoints = ["/api/pages/export", "/api/spaces/export"];
|
|
if (response.request.responseURL) {
|
|
const path = new URL(response.request.responseURL)?.pathname;
|
|
if (path && exemptEndpoints.includes(path)) {
|
|
return response;
|
|
}
|
|
}
|
|
|
|
return response.data;
|
|
},
|
|
(error) => {
|
|
if (error.response) {
|
|
switch (error.response.status) {
|
|
case 401: {
|
|
const url = new URL(error.request.responseURL)?.pathname;
|
|
if (url === "/api/auth/collab-token") return;
|
|
if (window.location.pathname.startsWith("/share/")) return;
|
|
|
|
// Handle unauthorized error
|
|
redirectToLogin();
|
|
break;
|
|
}
|
|
case 403:
|
|
// Handle forbidden error
|
|
break;
|
|
case 404:
|
|
// Handle not found error
|
|
if (
|
|
error.response.data.message
|
|
.toLowerCase()
|
|
.includes("workspace not found")
|
|
) {
|
|
console.log("workspace not found");
|
|
if (
|
|
!isCloud() &&
|
|
window.location.pathname != APP_ROUTE.AUTH.SETUP
|
|
) {
|
|
window.location.href = APP_ROUTE.AUTH.SETUP;
|
|
}
|
|
}
|
|
break;
|
|
case 500:
|
|
// Handle internal server error
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return Promise.reject(error);
|
|
},
|
|
);
|
|
|
|
function redirectToLogin() {
|
|
const exemptPaths = [
|
|
APP_ROUTE.AUTH.LOGIN,
|
|
APP_ROUTE.AUTH.SIGNUP,
|
|
APP_ROUTE.AUTH.FORGOT_PASSWORD,
|
|
APP_ROUTE.AUTH.PASSWORD_RESET,
|
|
"/invites",
|
|
];
|
|
if (!exemptPaths.some((path) => window.location.pathname.startsWith(path))) {
|
|
window.location.href = APP_ROUTE.AUTH.LOGIN;
|
|
}
|
|
}
|
|
|
|
export default api;
|