index.community/frontend/src/util.ts

19 lines
833 B
TypeScript
Raw Normal View History

import { createMatchSelector } from "connected-react-router";
2019-02-21 12:33:07 +00:00
import fetch from "cross-fetch";
import { IInstanceDomainPath, INSTANCE_DOMAIN_PATH } from "./constants";
import { IAppState } from "./redux/types";
2018-08-27 21:31:27 +00:00
let API_ROOT = "http://localhost:4000/api/";
if (["true", true, 1, "1"].indexOf(process.env.REACT_APP_STAGING || "") > -1) {
API_ROOT = "https://phoenix.api-develop.fediverse.space/api/";
} else if (process.env.NODE_ENV === "production") {
API_ROOT = "https://phoenix.api.fediverse.space/api/";
}
2018-08-27 21:31:27 +00:00
export const getFromApi = (path: string): Promise<any> => {
2019-02-21 12:33:07 +00:00
const domain = API_ROOT.endsWith("/") ? API_ROOT : API_ROOT + "/";
return fetch(encodeURI(domain + path)).then(response => response.json());
2019-02-21 12:33:07 +00:00
};
export const domainMatchSelector = createMatchSelector<IAppState, IInstanceDomainPath>(INSTANCE_DOMAIN_PATH);