Skip to content

Commit

Permalink
Fix issue with same domain servers stomping each other's API paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 10, 2023
1 parent 6c17b81 commit d28ba20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ApiClient/util/ConfigController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import configOptions, { ConfigOption, ConfigValue } from "./config";
import configOptions, { BaseConfigOption, ConfigOption, ConfigValue } from "./config";

export default new (class ConfigController {
public loadconfig() {
Expand All @@ -15,6 +15,12 @@ export default new (class ConfigController {
console.log("Configuration saved", configOptions);
}

private getConfigKey(option: BaseConfigOption): string {
if (!option.site_local) return option.id;

return `${window.location.pathname}:${option.id}`;
}

private setconfig(key: keyof typeof configOptions, option: ConfigOption) {
if (option?.value === undefined) return this.deleteconfig(key);

Expand Down Expand Up @@ -42,7 +48,7 @@ export default new (class ConfigController {
//if (!option.persist) return this.deleteconfig(key); //idiot proofing, alexkar proofing

try {
localStorage.setItem(option.id, JSON.stringify(option.value));
localStorage.setItem(this.getConfigKey(option), JSON.stringify(option.value));
//option.persist = true;
} catch (e) {
(() => {})(); //noop
Expand All @@ -51,7 +57,7 @@ export default new (class ConfigController {

private getconfig(option: ConfigOption): void {
try {
const data = localStorage.getItem(option.id);
const data = localStorage.getItem(this.getConfigKey(option));
if (data !== undefined && data !== null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const json = JSON.parse(data);
Expand All @@ -68,7 +74,7 @@ export default new (class ConfigController {
private deleteconfig(key: keyof typeof configOptions): void {
try {
const option = configOptions[key];
localStorage.removeItem(option.id);
localStorage.removeItem(this.getConfigKey(option));
//option.persist = false;
} catch (e) {
(() => {})(); //noop
Expand Down
2 changes: 2 additions & 0 deletions src/ApiClient/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ConfigOption = BaseConfigOption &

export interface BaseConfigOption {
id: string;
site_local?: boolean;
}

export interface NumConfigOption extends BaseConfigOption {
Expand Down Expand Up @@ -71,6 +72,7 @@ const configOptions = asElementTypesConfig({
apipath: {
id: "config.apipath",
type: "str",
site_local: true,
value:
MODE === "DEV"
? DEFAULT_APIPATH
Expand Down

0 comments on commit d28ba20

Please sign in to comment.