1
0

25 lines
889 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
function debounce<T extends (...args: any[]) => void>(fn: T, ms: number): T {
let timer: any = null;
return function(...args: Parameters<T>) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
timer = null;
fn.apply(this, args);
}, ms);
} as T;
};
// Prefer an explicit API base provided via environment variable. This allows
// the client running in a container to talk to the server by docker service
// name (e.g. http://peddlers-of-ketran:8930) while still working when run on
// the host where PUBLIC_URL may be appropriate.
const envApiBase = process.env.REACT_APP_API_BASE;
const publicBase = process.env.PUBLIC_URL || '';
const base = envApiBase || publicBase;
const assetsPath = `${publicBase}/assets`;
const gamesPath = `${base}`;
export { base, debounce, assetsPath, gamesPath };