From 3e609bec093c53387996f57c8b7dfbddd4f48be1 Mon Sep 17 00:00:00 2001 From: isstuev Date: Mon, 1 May 2023 12:54:24 -0300 Subject: [PATCH] add variable for ws protocol --- .env.template | 1 + configs/app/config.ts | 4 +++- docs/ENVS.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 1fc6572a08..46610f1d09 100644 --- a/.env.template +++ b/.env.template @@ -50,6 +50,7 @@ NEXT_PUBLIC_API_HOST=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_HOST__ NEXT_PUBLIC_API_BASE_PATH=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_BASE_PATH__ NEXT_PUBLIC_API_PROTOCOL=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_PROTOCOL__ NEXT_PUBLIC_API_PORT=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_PORT__ +NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL__ NEXT_PUBLIC_STATS_API_HOST=__PLACEHOLDER_FOR_NEXT_PUBLIC_STATS_API_HOST__ NEXT_PUBLIC_VISUALIZE_API_HOST=__PLACEHOLDER_FOR_NEXT_PUBLIC_VISUALIZE_API_HOST__ NEXT_PUBLIC_API_SPEC_URL=__PLACEHOLDER_FOR_NEXT_PUBLIC_API_SPEC_URL__ diff --git a/configs/app/config.ts b/configs/app/config.ts index bea02d5177..bc24581801 100644 --- a/configs/app/config.ts +++ b/configs/app/config.ts @@ -35,6 +35,8 @@ const apiEndpoint = apiHost ? [ apiPort && ':' + apiPort, ].filter(Boolean).join('') : 'https://blockscout.com'; +const socketSchema = getEnvValue(process.env.NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL) || 'wss'; + const logoutUrl = (() => { try { const envUrl = getEnvValue(process.env.NEXT_PUBLIC_LOGOUT_URL); @@ -106,7 +108,7 @@ const config = Object.freeze({ api: { host: apiHost, endpoint: apiEndpoint, - socket: apiHost ? `wss://${ apiHost }` : 'wss://blockscout.com', + socket: apiHost ? `${ socketSchema }://${ apiHost }` : 'wss://blockscout.com', basePath: stripTrailingSlash(getEnvValue(process.env.NEXT_PUBLIC_API_BASE_PATH) || ''), }, L2: { diff --git a/docs/ENVS.md b/docs/ENVS.md index 11dbd48085..863a1137dd 100644 --- a/docs/ENVS.md +++ b/docs/ENVS.md @@ -119,8 +119,10 @@ For each application, you need to specify the `MarketplaceCategoryId` to which i | Variable | Type| Description | Is required | Default value | Example value | | --- | --- | --- | --- | --- | --- | +| NEXT_PUBLIC_API_PROTOCOL | `http \| https` | Main API protocol | - | `https` | `http` | | NEXT_PUBLIC_API_HOST | `string` | Main API host | - | `blockscout.com` | `my-host.com` | | NEXT_PUBLIC_API_BASE_PATH | `string` | Base path for Main API endpoint url | - | - | `/poa/core` | +| NEXT_PUBLIC_API_WEBSOCKET_PROTOCOL | `ws \| wss` | Main API websocket protocol | - | `wss` | `ws` | | NEXT_PUBLIC_STATS_API_HOST | `string` | Stats API endpoint url | - | - | `https://my-host.com` | | NEXT_PUBLIC_VISUALIZE_API_HOST | `string` | Visualize API endpoint url | - | - | `https://my-host.com` |