Skip to content

Commit

Permalink
Refactor configuration API to use CONFIG_PATH instead of ENV_CONFIG
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP committed Oct 22, 2024
1 parent 74ac4e9 commit f24b618
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ data:
NODE_ENV: "production"
TZ: "Europe/Berlin"
PORT: "3046"
ENV_CONFIG: "{{ '/api/tldraw/config/public' if WITH_TLDRAW2 else '/api/v3/config/public' }}"
CONFIG_PATH: "{{ '/api/tldraw/config/public' if WITH_TLDRAW2 else '/api/v3/config/public' }}"
2 changes: 1 addition & 1 deletion nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ server {
set $csp "default-src 'self'; connect-src 'self' data:; base-uri 'self'; script-src 'nonce-$request_id' 'strict-dynamic' https:; object-src 'none'; font-src 'self' data:; img-src 'self' data:; style-src 'self' 'unsafe-inline';";

location /tldraw-client-runtime.config.json {
return 200 '{ "ENV_CONFIG": "${ENV_CONFIG}" }';
return 200 '{ "CONFIG_PATH": "${CONFIG_PATH}" }';
add_header Content-Type application/json;
}

Expand Down
12 changes: 6 additions & 6 deletions src/configuration/api/api.configuration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// remove this code by BC-7906
// set ENV_CONFIG to /api/tldraw/config/public
// set CONFIG_PATH to /api/tldraw/config/public
// remove line 7 and 8 in ngnix.conf.template
import { HttpStatusCode } from "../../types/StatusCodeEnums";
import { setErrorData } from "../../utils/errorData";
import { redirectToErrorPage } from "../../utils/redirectUtils";

const getConfigOptions = async (): Promise<{
ENV_CONFIG: string;
CONFIG_PATH: string;
}> => {
const connectionOptions = {
ENV_CONFIG: configApiUrl(),
CONFIG_PATH: configApiUrl(),
};

if (import.meta.env.PROD) {
Expand All @@ -20,8 +20,8 @@ const getConfigOptions = async (): Promise<{
throw new Error(`${response.status} - ${response.statusText}`);
}

const data: { ENV_CONFIG: string } = await response.json();
connectionOptions.ENV_CONFIG = data.ENV_CONFIG;
const data: { CONFIG_PATH: string } = await response.json();
connectionOptions.CONFIG_PATH = data.CONFIG_PATH;
} catch (error) {
setErrorData(HttpStatusCode.InternalServerError, "error.500");
redirectToErrorPage();
Expand All @@ -45,5 +45,5 @@ export const API = {
FILE_RESTORE: "/api/v3/file/restore/FILERECORD_ID",
LOGIN_REDIRECT: "/login?redirect=/tldraw?parentId=PARENTID",
USER_DATA: `/api/v3/user/me`,
ENV_CONFIG: await getConfigOptions().then((options) => options.ENV_CONFIG),
CONFIG_PATH: await getConfigOptions().then((options) => options.CONFIG_PATH),
};
2 changes: 1 addition & 1 deletion src/utils/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { redirectToErrorPage } from "./redirectUtils";
export const getEnvs = async (): Promise<Envs> => {
try {
// TODO: check order..
const response = await fetch(API.ENV_CONFIG);
const response = await fetch(API.CONFIG_PATH);
HttpGuard.checkStatusOk(response);
const responseData = await response.json();

Expand Down

0 comments on commit f24b618

Please sign in to comment.