Improve performance on mobile

This commit is contained in:
Michał Leszczyk 2022-04-05 13:17:17 +02:00
parent a3b21edf0c
commit 1a0fb9a806
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
2 changed files with 7 additions and 4 deletions

View File

@ -1,8 +1,11 @@
import { navigate } from "gatsby";
import { StatusCodes } from "http-status-codes";
// TODO: portal-aware URL
const baseUrl = process.env.NODE_ENV !== "production" ? "/api" : "https://account.skynetpro.net/api";
const redirectUnauthenticated = (key) =>
fetch(`/api/${key}`).then((response) => {
fetch(`${baseUrl}/${key}`).then((response) => {
if (response.status === StatusCodes.UNAUTHORIZED) {
navigate(`/auth/login?return_to=${encodeURIComponent(window.location.href)}`);
return null;
@ -12,7 +15,7 @@ const redirectUnauthenticated = (key) =>
});
const redirectAuthenticated = (key) =>
fetch(`/api/${key}`).then(async (response) => {
fetch(`${baseUrl}/${key}`).then(async (response) => {
if (response.ok) {
await navigate("/");
return response.json();
@ -24,7 +27,7 @@ const redirectAuthenticated = (key) =>
});
export const allUsers = {
fetcher: (key) => fetch(`/api/${key}`).then((response) => response.json()),
fetcher: (key) => fetch(`${baseUrl}/${key}`).then((response) => response.json()),
};
export const authenticatedOnly = {

View File

@ -1,3 +1,3 @@
import { SkynetClient } from "skynet-js";
export default new SkynetClient(`https://${process.env.GATSBY_PORTAL_DOMAIN}`);
export default new SkynetClient("https://skynetpro.net"); // TODO: proper API url