Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:editors): use configured public URL for editor endpoints
johavenfe3345df0b91
diff --git a/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.spec.ts b/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.spec.tsindex f4c00860..aa31fac8 100644--- a/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.spec.ts+++ b/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.spec.ts@@ -60,7 +60,7 @@ describe(CollaboraOnlineManager.name, () => {{provide: ContextManager,useValue: {- headerOriginUrl: vi.fn().mockReturnValue('https://domain.com')+ publicOriginUrl: vi.fn().mockReturnValue('https://domain.com')}},{diff --git a/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.ts b/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.tsindex e40e2ba4..a6ad790e 100644--- a/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.ts+++ b/backend/src/applications/files/editors/collabora-online/collabora-online-manager.service.ts@@ -226,7 +226,7 @@ export class CollaboraOnlineManager {}private getDocumentUrl(dbFileHash: string, token: string): string {- const collaboraBase = this.externalCollaboraOnlineServer || this.contextManager.headerOriginUrl()+ const collaboraBase = this.externalCollaboraOnlineServer || this.contextManager.publicOriginUrl()// Example:// - external: https://collabora.domain.com// - internal (via nginx proxy): https://domain.com/*@@ -234,7 +234,7 @@ export class CollaboraOnlineManager {const editorUrl = new URL(COLLABORA_URI, collaboraBase)// → /browser/dist/cool.html- const wopiSrcUrl = new URL(`${API_COLLABORA_ONLINE_FILES}/${dbFileHash}`, this.contextManager.headerOriginUrl())+ const wopiSrcUrl = new URL(`${API_COLLABORA_ONLINE_FILES}/${dbFileHash}`, this.contextManager.publicOriginUrl())// → https://domain.com/wopi/files/888editorUrl.searchParams.set(COLLABORA_WOPI_SRC_QUERY_PARAM_NAME, wopiSrcUrl.toString())diff --git a/backend/src/applications/files/editors/only-office/only-office-manager.service.spec.ts b/backend/src/applications/files/editors/only-office/only-office-manager.service.spec.tsindex 8d97fe45..a5136857 100644--- a/backend/src/applications/files/editors/only-office/only-office-manager.service.spec.ts+++ b/backend/src/applications/files/editors/only-office/only-office-manager.service.spec.ts@@ -99,7 +99,7 @@ describe(OnlyOfficeManager.name, () => {{provide: ContextManager,useValue: {- headerOriginUrl: vi.fn().mockReturnValue('http://localhost:3000')+ publicOriginUrl: vi.fn().mockReturnValue('http://localhost:3000')}},{diff --git a/backend/src/applications/files/editors/only-office/only-office-manager.service.ts b/backend/src/applications/files/editors/only-office/only-office-manager.service.tsindex c2911144..1dc3253d 100644--- a/backend/src/applications/files/editors/only-office/only-office-manager.service.ts+++ b/backend/src/applications/files/editors/only-office/only-office-manager.service.ts@@ -178,7 +178,7 @@ export class OnlyOfficeManager {const documentType = ONLY_OFFICE_EXTENSIONS.get(fileExtension)return {hasLock: hasLock,- documentServerUrl: this.externalOnlyOfficeServer || `${this.contextManager.headerOriginUrl()}${ONLY_OFFICE_INTERNAL_URI}`,+ documentServerUrl: this.externalOnlyOfficeServer || `${this.contextManager.publicOriginUrl()}${ONLY_OFFICE_INTERNAL_URI}`,config: {type: isMobile ? 'mobile' : 'desktop',height: '100%',@@ -230,7 +230,7 @@ export class OnlyOfficeManager {}private buildUrl(basePath: string, spaceUrl: string, token: string): string {- const url = new URL(`${basePath}/${spaceUrl}`, this.contextManager.headerOriginUrl())+ const url = new URL(`${basePath}/${spaceUrl}`, this.contextManager.publicOriginUrl())url.searchParams.set(ONLY_OFFICE_TOKEN_QUERY_PARAM_NAME, token)return url.toString()}diff --git a/backend/src/infrastructure/context/services/context-manager.service.spec.ts b/backend/src/infrastructure/context/services/context-manager.service.spec.tsindex 63069e5e..d0ec831d 100644--- a/backend/src/infrastructure/context/services/context-manager.service.spec.ts+++ b/backend/src/infrastructure/context/services/context-manager.service.spec.ts@@ -1,9 +1,11 @@import { Test, TestingModule } from '@nestjs/testing'+import { configuration } from '../../../configuration/config.environment'import type { ContextStore } from '../interfaces/context-store.interface'import { ContextManager } from './context-manager.service'describe(ContextManager.name, () => {let contextManager: ContextManager+ const initialPublicUrl = configuration.server.publicUrlbeforeAll(async () => {const module: TestingModule = await Test.createTestingModule({@@ -13,6 +15,14 @@ describe(ContextManager.name, () => {contextManager = module.get<ContextManager>(ContextManager)})+ beforeEach(() => {+ configuration.server.publicUrl = undefined+ })++ afterAll(() => {+ configuration.server.publicUrl = initialPublicUrl+ })+it('should be defined', () => {expect(contextManager).toBeDefined()})@@ -20,15 +30,23 @@ describe(ContextManager.name, () => {const runWithContext = <T>(ctx: ContextStore, fn: () => T): T => contextManager.run(ctx, fn) as unknown as Tdescribe('Context access', () => {- it('headerOriginUrl() should return undefined when no context is active', () => {- expect(contextManager.headerOriginUrl()).toBeUndefined()+ it('publicOriginUrl() should return undefined when no URL is configured and no context is active', () => {+ expect(contextManager.publicOriginUrl()).toBeUndefined()+ })++ it('publicOriginUrl() should prefer the configured public URL and preserve its port', () => {+ configuration.server.publicUrl = 'http://192.168.62.131:8060'++ runWithContext({ headerOriginUrl: 'https://request-origin.example' }, () => {+ expect(contextManager.publicOriginUrl()).toBe('http://192.168.62.131:8060')+ })})it('run() should expose context within the callback and surface return value', () => {const ctx = { headerOriginUrl: 'https://sync-in.example' }const value = runWithContext<number>(ctx, () => {- expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(ctx.headerOriginUrl)return 123})@@ -41,10 +59,10 @@ describe(ContextManager.name, () => {const ctx = { headerOriginUrl: 'https://sync-in.example' }runWithContext<void>(ctx, () => {- expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(ctx.headerOriginUrl)})- expect(contextManager.headerOriginUrl()).toBeUndefined()+ expect(contextManager.publicOriginUrl()).toBeUndefined()})it('should support nested contexts and restore the previous one after inner run()', () => {@@ -52,16 +70,16 @@ describe(ContextManager.name, () => {const inner = { headerOriginUrl: 'https://inner.example' }runWithContext<void>(outer, () => {- expect(contextManager.headerOriginUrl()).toBe(outer.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(outer.headerOriginUrl)runWithContext<void>(inner, () => {- expect(contextManager.headerOriginUrl()).toBe(inner.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(inner.headerOriginUrl)})- expect(contextManager.headerOriginUrl()).toBe(outer.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(outer.headerOriginUrl)})- expect(contextManager.headerOriginUrl()).toBeUndefined()+ expect(contextManager.publicOriginUrl()).toBeUndefined()})})@@ -71,7 +89,7 @@ describe(ContextManager.name, () => {await runWithContext<Promise<void>>(ctx, async () => {await Promise.resolve()- expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(ctx.headerOriginUrl)})})@@ -81,7 +99,7 @@ describe(ContextManager.name, () => {await runWithContext<Promise<void>>(ctx, async () => {await new Promise<void>((resolve) =>setTimeout(() => {- expect(contextManager.headerOriginUrl()).toBe(ctx.headerOriginUrl)+ expect(contextManager.publicOriginUrl()).toBe(ctx.headerOriginUrl)resolve()}, 0))diff --git a/backend/src/infrastructure/context/services/context-manager.service.ts b/backend/src/infrastructure/context/services/context-manager.service.tsindex 3675c2cf..0ad59f69 100644--- a/backend/src/infrastructure/context/services/context-manager.service.ts+++ b/backend/src/infrastructure/context/services/context-manager.service.ts@@ -1,6 +1,7 @@import { Injectable } from '@nestjs/common'import { AsyncLocalStorage } from 'node:async_hooks'import type { Observable } from 'rxjs'+import { configuration } from '../../../configuration/config.environment'import type { ContextStore } from '../interfaces/context-store.interface'@Injectable()@@ -11,8 +12,12 @@ export class ContextManager {this.storage = new AsyncLocalStorage<ContextStore>()}- headerOriginUrl(): string {- return this.storage.getStore() ? this.storage.getStore().headerOriginUrl : undefined+ /**+ * @deprecated Temporary compatibility helper while server.publicUrl is optional.+ * It will be removed in the next major release when server.publicUrl becomes required.+ */+ publicOriginUrl(): string | undefined {+ return configuration.server.publicUrl ?? this.storage.getStore()?.headerOriginUrl}run(context: ContextStore, cb: () => unknown): Observable<unknown> {diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yamlindex 02862439..ea52d196 100644--- a/environment/environment.dist.yaml+++ b/environment/environment.dist.yaml@@ -3,8 +3,8 @@ server:host: 0.0.0.0# default port : `8080`port: 8080- # publicUrl: Canonical public URL used to build links in notification emails.- # When unset, notification emails are sent without action links.+ # publicUrl: Canonical public URL used to build notification links and document editor URLs.+ # When unset, notification emails are sent without action links and document editors fall back to the request origin.# It will become required in a future major release.# e.g.: https://sync-in.domain.com# optional