| 5 | export const API_GATEWAY_PATH = "https://api2.matterai.so/v1/web/"; |
| 6 | |
| 7 | export function getBaseUrlFromToken(token?: string): string { |
| 8 | if (token) { |
| 9 | try { |
| 10 | const payloadString = token.split(".")[1]; |
| 11 | if (payloadString) { |
| 12 | const payload = JSON.parse( |
| 13 | Buffer.from(payloadString, "base64").toString(), |
| 14 | ); |
| 15 | // UNTRUSTED payload: only used to detect the development environment, |
| 16 | // never to read URLs directly. |
| 17 | if (payload.env === "development") return "http://localhost:3000"; |
| 18 | } |
| 19 | } catch { |
| 20 | // fall through to production URL |
| 21 | } |
| 22 | } |
| 23 | return DEFAULT_BACKEND_URL; |
| 24 | } |
| 25 | |
| 26 | /** Re-host targetUrl onto the backend resolved from the token. */ |
| 27 | export function getUrlFromToken(targetUrl: string, token?: string): string { |