Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(desktop): send official API traffic to fluxer.com (#3808)

Hampusd6f6c409ee19
diff --git a/fluxer_api/src/api/Config.ts b/fluxer_api/src/api/Config.ts
index 5b4ab6b3c..f8ecb2504 100644
--- a/fluxer_api/src/api/Config.ts
+++ b/fluxer_api/src/api/Config.ts
@@ -436,6 +436,7 @@ export function buildAPIConfigFromMaster(master: MasterConfig): APIConfig {
endpoints: {
apiPublic: master.endpoints.api,
apiPublicDiscovery: master.services.api.discovery_public_endpoint || master.endpoints.api,
+ apiTransportDiscovery: master.services.api.discovery_transport_endpoint || null,
apiClient: master.endpoints.api_client,
webApp: master.endpoints.app,
webAppOrigins: [...new Set([new URL(master.endpoints.app).origin, ...master.services.api.app_origin_aliases])],
diff --git a/fluxer_api/src/api/config/APIConfig.ts b/fluxer_api/src/api/config/APIConfig.ts
index 7762ef1ac..bdb897ac0 100644
--- a/fluxer_api/src/api/config/APIConfig.ts
+++ b/fluxer_api/src/api/config/APIConfig.ts
@@ -158,6 +158,7 @@ export interface APIConfig {
endpoints: {
apiPublic: string;
apiPublicDiscovery: string;
+ apiTransportDiscovery: string | null;
apiClient: string;
webApp: string;
webAppOrigins: Array<string>;
diff --git a/fluxer_api/src/api/instance/InstanceController.ts b/fluxer_api/src/api/instance/InstanceController.ts
index d46c1c931..be9bd5f49 100644
--- a/fluxer_api/src/api/instance/InstanceController.ts
+++ b/fluxer_api/src/api/instance/InstanceController.ts
@@ -110,6 +110,7 @@ function buildDiscoveryStaticInput(
api: apiClientEndpoint,
api_client: apiClientEndpoint,
api_public: apiPublicEndpoint,
+ ...(Config.endpoints.apiTransportDiscovery ? {api_transport: Config.endpoints.apiTransportDiscovery} : {}),
gateway: Config.endpoints.gateway,
media: Config.endpoints.media,
upload_relay: Config.mediaProxy.uploadRelay.endpoint,
diff --git a/fluxer_api/src/api/openapi/openapi.json b/fluxer_api/src/api/openapi/openapi.json
index 182643140..9de5fdf4b 100644
--- a/fluxer_api/src/api/openapi/openapi.json
+++ b/fluxer_api/src/api/openapi/openapi.json
@@ -39115,6 +39115,10 @@
"api": {"type": "string", "description": "Base URL for authenticated API requests"},
"api_client": {"type": "string", "description": "Base URL for client API requests"},
"api_public": {"type": "string", "description": "Base URL for public API requests"},
+ "api_transport": {
+ "description": "Base URL that official desktop clients send API requests to instead of api_client",
+ "type": "string"
+ },
"gateway": {"type": "string", "description": "WebSocket URL for the gateway"},
"media": {"type": "string", "description": "Base URL for the media proxy"},
"upload_relay": {"description": "Base URL for proxied attachment and preview uploads", "type": "string"},
diff --git a/fluxer_desktop/src/main/LocalAppAPIProxyRequestHandler.ts b/fluxer_desktop/src/main/LocalAppAPIProxyRequestHandler.ts
index 845db6552..aa1601536 100644
--- a/fluxer_desktop/src/main/LocalAppAPIProxyRequestHandler.ts
+++ b/fluxer_desktop/src/main/LocalAppAPIProxyRequestHandler.ts
@@ -76,7 +76,7 @@ export class DesktopLocalAppAPIProxyRequestHandler {
private async forward({request, plan, localPathPrefix, signal}: ForwardAPIProxyRequest): Promise<Response> {
const uploadId = readLocalAppUploadId(request.headers);
const targetURL = buildAPITargetURL({
- apiEndpoint: plan.endpoints.apiEndpoint,
+ apiEndpoint: plan.endpoints.apiTransportEndpoint ?? plan.endpoints.apiEndpoint,
requestURL: request.url,
localPathPrefix,
});
diff --git a/fluxer_desktop/src/main/LocalAppRuntimePlans.ts b/fluxer_desktop/src/main/LocalAppRuntimePlans.ts
index 0f5efa9bb..ac87d2d6c 100644
--- a/fluxer_desktop/src/main/LocalAppRuntimePlans.ts
+++ b/fluxer_desktop/src/main/LocalAppRuntimePlans.ts
@@ -13,6 +13,7 @@ const ROUTE_CACHE_KEY_PREFIX = 'route:';
interface LocalAppRuntimeEndpoints {
readonly apiEndpoint: string;
+ readonly apiTransportEndpoint: string | null;
readonly apiPublicEndpoint: string | null;
readonly webAppEndpoint: string | null;
readonly mediaEndpoint: string | null;
@@ -130,6 +131,7 @@ export function runtimePlanTrustedHTTPOrigins(plan: LocalAppRuntimePlan): Array<
const endpoints = plan.endpoints;
const httpEndpoints: ReadonlyArray<string | null> = [
endpoints.apiEndpoint,
+ endpoints.apiTransportEndpoint,
endpoints.apiPublicEndpoint,
endpoints.mediaEndpoint,
endpoints.uploadRelayEndpoint,
@@ -209,6 +211,7 @@ function runtimeEndpointsFromDiscovery(discovery: ClientRuntimeDiscovery): Local
const endpoints = discovery.endpoints;
return {
apiEndpoint: endpoints.apiEndpoint,
+ apiTransportEndpoint: endpoints.apiTransportEndpoint,
apiPublicEndpoint: endpoints.apiPublicEndpoint,
webAppEndpoint: endpoints.webAppEndpoint,
mediaEndpoint: endpoints.mediaEndpoint,
diff --git a/fluxer_docs/src/content/docs/http-api/instance.mdx b/fluxer_docs/src/content/docs/http-api/instance.mdx
index 869b3c514..7993a7ab3 100644
--- a/fluxer_docs/src/content/docs/http-api/instance.mdx
+++ b/fluxer_docs/src/content/docs/http-api/instance.mdx
@@ -105,6 +105,7 @@ Each value is an absolute URL. Use it exactly as published, including its scheme
| api | string | Base URL of the client API, the same as `api_client` |
| api_client | string | Base URL of the client API, used by the Fluxer apps |
| api_public | string | Base URL of the public API, used by bots and other clients |
+| api_transport? | string | Base URL the official desktop app sends API requests to instead of `api_client`. Only Fluxer.app lists it, and the app ignores any address other than the matching fluxer.com one |
| gateway | string | The [Gateway](/gateway/overview/) WebSocket URL, with a `ws` or `wss` scheme |
| media | string | [Media Proxy](/media-proxy/overview/) base URL |
| upload_relay? | string | Attachment [upload relay](/media-proxy/upload-relay/) base URL |
diff --git a/packages/config/src/ConfigLoader.ts b/packages/config/src/ConfigLoader.ts
index d77b1743a..b392bee10 100644
--- a/packages/config/src/ConfigLoader.ts
+++ b/packages/config/src/ConfigLoader.ts
@@ -114,6 +114,7 @@ function defaultConfig(): MasterConfig {
unfurl_ignored_hosts: [],
app_origin_aliases: [],
discovery_public_endpoint: '',
+ discovery_transport_endpoint: '',
storage_change_feed: {
enabled: false,
stream: 'STORAGE_CHANGES',
diff --git a/packages/config/src/MasterConfig.ts b/packages/config/src/MasterConfig.ts
index c18c0b722..70afd9931 100644
--- a/packages/config/src/MasterConfig.ts
+++ b/packages/config/src/MasterConfig.ts
@@ -123,6 +123,7 @@ export interface MasterConfig {
unfurl_ignored_hosts: Array<string>;
app_origin_aliases: Array<string>;
discovery_public_endpoint: string;
+ discovery_transport_endpoint: string;
worker?: {
mode?: 'all_lanes' | 'single_lane' | 'single_task';
lane?: 'realtime' | 'unfurl' | 'lifecycle' | 'batch' | 'crosspost';
diff --git a/packages/config/src/config_loader/EnvironmentOverrides.ts b/packages/config/src/config_loader/EnvironmentOverrides.ts
index e944dc50b..b7377b4c7 100644
--- a/packages/config/src/config_loader/EnvironmentOverrides.ts
+++ b/packages/config/src/config_loader/EnvironmentOverrides.ts
@@ -112,6 +112,7 @@ const NAMED_FLUXER_ENV_OVERRIDES: Record<string, NamedEnvOverride> = {
FLUXER_API_UNFURL_IGNORED_HOSTS: {path: ['services', 'api', 'unfurl_ignored_hosts'], parse: parseCsv},
FLUXER_APP_ORIGIN_ALIASES: {path: ['services', 'api', 'app_origin_aliases'], parse: parseCsv},
FLUXER_API_DISCOVERY_PUBLIC_ENDPOINT: {path: ['services', 'api', 'discovery_public_endpoint']},
+ FLUXER_API_DISCOVERY_TRANSPORT_ENDPOINT: {path: ['services', 'api', 'discovery_transport_endpoint']},
FLUXER_MEDIA_PROXY_SECRET_KEY: {path: ['services', 'media_proxy', 'secret_key']},
FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT: {path: ['services', 'media_proxy', 'upload_relay', 'endpoint']},
FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64: {path: ['services', 'media_proxy', 'upload_relay', 'secret_base64']},
diff --git a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
index becb14fbc..a2bbd52eb 100644
--- a/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
+++ b/packages/instance_bootstrap/src/ClientRuntimeDiscovery.ts
@@ -5,6 +5,7 @@ import {
type InstanceGeneration,
InvalidInstanceDiscoveryDocumentError,
} from '@fluxer/instance_bootstrap/src/Discovery';
+import {officialClientApiTransportEndpoint} from '@fluxer/instance_bootstrap/src/OfficialInstance';
import type {
InstanceAgePolicy,
InstanceAppPublic,
@@ -35,6 +36,7 @@ export interface ClientRuntimeDiscoveryEndpoints {
readonly discoveryApiEndpoint: string;
readonly apiEndpoint: string;
readonly apiPublicEndpoint: string;
+ readonly apiTransportEndpoint: string | null;
readonly gatewayEndpoint: string;
readonly mediaEndpoint: string;
readonly uploadRelayEndpoint: string | null;
@@ -101,6 +103,10 @@ function projectEndpoints(document: InstanceDiscoveryDocument): ClientRuntimeDis
discoveryApiEndpoint: endpoints.api,
apiEndpoint: requireValue(endpoints.api_client, 'endpoints.api_client'),
apiPublicEndpoint: requireValue(endpoints.api_public, 'endpoints.api_public'),
+ apiTransportEndpoint: vettedApiTransportEndpoint(
+ requireValue(endpoints.api_client, 'endpoints.api_client'),
+ endpoints.api_transport,
+ ),
gatewayEndpoint: endpoints.gateway,
mediaEndpoint: requireValue(endpoints.media, 'endpoints.media'),
uploadRelayEndpoint: endpoints.upload_relay,
@@ -114,6 +120,12 @@ function projectEndpoints(document: InstanceDiscoveryDocument): ClientRuntimeDis
};
}
+function vettedApiTransportEndpoint(apiEndpoint: string, advertised: string | null): string | null {
+ if (advertised == null) return null;
+ const allowed = officialClientApiTransportEndpoint(apiEndpoint);
+ return allowed !== null && allowed === advertised ? allowed : null;
+}
+
function projectFeatures(features: Readonly<Partial<InstanceFeatures>>): InstanceFeatures {
return {
...features,
diff --git a/packages/instance_bootstrap/src/Discovery.ts b/packages/instance_bootstrap/src/Discovery.ts
index 0afb06dc5..ff725d108 100644
--- a/packages/instance_bootstrap/src/Discovery.ts
+++ b/packages/instance_bootstrap/src/Discovery.ts
@@ -113,6 +113,7 @@ interface InstanceDiscoveryEndpoints {
readonly gateway: string;
readonly api_client: string | null;
readonly api_public: string | null;
+ readonly api_transport: string | null;
readonly media: string | null;
readonly upload_relay: string | null;
readonly static_cdn: string | null;
@@ -543,6 +544,7 @@ function parseEndpoints(value: unknown): InstanceDiscoveryEndpoints {
gateway,
api_client: normalizeInstanceEndpoint(source.api_client, InstanceEndpointKind.SERVICE),
api_public: normalizeInstanceEndpoint(source.api_public, InstanceEndpointKind.SERVICE),
+ api_transport: normalizeInstanceEndpoint(source.api_transport, InstanceEndpointKind.SERVICE),
media: normalizeInstanceEndpoint(source.media, InstanceEndpointKind.SERVICE),
upload_relay: normalizeInstanceEndpoint(source.upload_relay, InstanceEndpointKind.SERVICE),
static_cdn: normalizeInstanceEndpoint(source.static_cdn, InstanceEndpointKind.SERVICE),
diff --git a/packages/instance_bootstrap/src/OfficialInstance.ts b/packages/instance_bootstrap/src/OfficialInstance.ts
index dbc24e18e..08dec56f4 100644
--- a/packages/instance_bootstrap/src/OfficialInstance.ts
+++ b/packages/instance_bootstrap/src/OfficialInstance.ts
@@ -21,6 +21,20 @@ export const OFFICIAL_CLIENT_API_ENDPOINTS = Object.freeze({
export type OfficialReleaseChannel = keyof typeof OFFICIAL_CLIENT_API_ENDPOINTS;
+const OFFICIAL_CLIENT_API_TRANSPORT_ENDPOINTS = Object.freeze({
+ stable: 'https://fluxer.com/api',
+ canary: 'https://canary.fluxer.com/api',
+} as const) satisfies Record<OfficialReleaseChannel, string>;
+
+export function officialClientApiTransportEndpoint(apiEndpoint: string): string | null {
+ for (const channel of Object.keys(OFFICIAL_CLIENT_API_ENDPOINTS) as Array<OfficialReleaseChannel>) {
+ if (OFFICIAL_CLIENT_API_ENDPOINTS[channel] === apiEndpoint) {
+ return OFFICIAL_CLIENT_API_TRANSPORT_ENDPOINTS[channel];
+ }
+ }
+ return null;
+}
+
export const OFFICIAL_MARKETING_ORIGINS = Object.freeze({
stable: OFFICIAL_STABLE_MARKETING_ORIGIN,
canary: 'https://canary.fluxer.com',
diff --git a/packages/schema/src/domains/instance/InstanceSchemas.ts b/packages/schema/src/domains/instance/InstanceSchemas.ts
index 66dd74199..c5a1845d0 100644
--- a/packages/schema/src/domains/instance/InstanceSchemas.ts
+++ b/packages/schema/src/domains/instance/InstanceSchemas.ts
@@ -175,6 +175,10 @@ export const InstanceEndpointsSchema = z
api: z.string().describe('Base URL for authenticated API requests'),
api_client: z.string().describe('Base URL for client API requests'),
api_public: z.string().describe('Base URL for public API requests'),
+ api_transport: z
+ .string()
+ .optional()
+ .describe('Base URL that official desktop clients send API requests to instead of api_client'),
gateway: z.string().describe('WebSocket URL for the gateway'),
media: z.string().describe('Base URL for the media proxy'),
upload_relay: z.string().optional().describe('Base URL for proxied attachment and preview uploads'),