From 535512d4e40311bc76c402c506d392c97cc2886c Mon Sep 17 00:00:00 2001 From: ramiroaisen <52116153+ramiroaisen@users.noreply.github.com> Date: Mon, 3 Jul 2023 15:00:25 -0300 Subject: [PATCH] feat: add customizable cookie_domain to front hosts --- front/server/openstream-front.sample.jsonc | 42 +--------------------- front/server/openstream-front.sample.toml | 39 ++------------------ front/server/src/config.test.ts | 8 +++++ front/server/src/config.ts | 1 + front/server/src/session.ts | 2 +- 5 files changed, 13 insertions(+), 79 deletions(-) diff --git a/front/server/openstream-front.sample.jsonc b/front/server/openstream-front.sample.jsonc index 78da9f61..e0946f83 100644 --- a/front/server/openstream-front.sample.jsonc +++ b/front/server/openstream-front.sample.jsonc @@ -90,6 +90,7 @@ "hosts": { "default": { + "cookie_domain": "openstream.fm", "site": { "host": "openstream.fm" }, "studio": { "host": "studio.openstream.fm" }, "admin": { "host": "admin.openstream.fm" }, @@ -97,47 +98,6 @@ "storage": { "host": "storage.openstream.fm" }, "stream": { "host": "stream.openstream.fm" }, "source": { "host": "source.openstream.fm", "port": 8000 } - }, - - - "local": { - "site": { "host": "local.openstream.fm" }, - "studio": { "host": "studio.local.openstream.fm" }, - "admin": { "host": "admin.local.openstream.fm" }, - "api": { "host": "api.local.openstream.fm" }, - "storage": { "host": "storage.local.openstream.fm" }, - "stream": { "host": "stream.local.openstream.fm" }, - "source": { "host": "source.local.openstream.fm", "port": 8000 } - }, - - "s1": { - "site": { "host": "s1.openstream.fm" }, - "studio": { "host": "studio.s1.openstream.fm" }, - "admin": { "host": "admin.s1.openstream.fm" }, - "api": { "host": "api.s1.openstream.fm" }, - "storage": { "host": "storage.s1.openstream.fm" }, - "stream": { "host": "stream.s1.openstream.fm" }, - "source": { "host": "source.s1.openstream.fm", "port": 8100 } - }, - - "s2": { - "site": { "host": "s2.openstream.fm" }, - "studio": { "host": "studio.s2.openstream.fm" }, - "admin": { "host": "admin.s2.openstream.fm" }, - "api": { "host": "api.s2.openstream.fm" }, - "storage": { "host": "storage.s2.openstream.fm" }, - "stream": { "host": "stream.s2.openstream.fm" }, - "source": { "host": "source.s2.openstream.fm", "port": 8200 } - }, - - "test": { - "site": { "host": "test.openstream.fm" }, - "studio": { "host": "studio.test.openstream.fm" }, - "admin": { "host": "admin.test.openstream.fm" }, - "api": { "host": "api.test.openstream.fm" }, - "storage": { "host": "storage.test.openstream.fm" }, - "stream": { "host": "stream.test.openstream.fm" }, - "source": { "host": "source.test.openstream.fm", "port": 8001 } } } } \ No newline at end of file diff --git a/front/server/openstream-front.sample.toml b/front/server/openstream-front.sample.toml index 6a6feb57..5afd44e4 100644 --- a/front/server/openstream-front.sample.toml +++ b/front/server/openstream-front.sample.toml @@ -87,46 +87,11 @@ private_key = "" # hostnames configuration [hosts.default] +cookie_domain = "openstream.fm" site = { host = "openstream.fm" } studio = { host = "studio.openstream.fm" } admin = { host = "admin.openstream.fm" } api = { host = "api.openstream.fm" } storage = { host = "storage.openstream.fm" } stream = { host = "stream.openstream.fm" } -source = { host = "source.openstream.fm", port = 8000 } - -[hosts.local] -site = { host = "local.openstream.fm" } -studio = { host = "studio.local.openstream.fm" } -admin = { host = "admin.local.openstream.fm" } -api = { host = "api.local.openstream.fm" } -storage = { host = "storage.local.openstream.fm" } -stream = { host = "stream.local.openstream.fm" } -source = { host = "source.local.openstream.fm", port = 8000 } - -[hosts.s1] -site = { host = "s1.openstream.fm" } -studio = { host = "studio.s1.openstream.fm" } -admin = { host = "admin.s1.openstream.fm" } -api = { host = "api.s1.openstream.fm" } -storage = { host = "storage.s1.openstream.fm" } -stream = { host = "stream.s1.openstream.fm" } -source = { host = "source.s1.openstream.fm", port = 8100 } - -[hosts.s2] -site = { host = "s2.openstream.fm" } -studio = { host = "studio.s2.openstream.fm" } -admin = { host = "admin.s2.openstream.fm" } -api = { host = "api.s2.openstream.fm" } -storage = { host = "storage.s2.openstream.fm" } -stream = { host = "stream.s2.openstream.fm" } -source = { host = "source.s2.openstream.fm", port = 8200 } - -[hosts.test] -site = { host = "test.openstream.fm" } -studio = { host = "studio.test.openstream.fm" } -admin = { host = "admin.test.openstream.fm" } -api = { host = "api.test.openstream.fm" } -storage = { host = "storage.test.openstream.fm" } -stream = { host = "stream.test.openstream.fm" } -source = { host = "source.test.openstream.fm", port = 8001 } \ No newline at end of file +source = { host = "source.openstream.fm", port = 8000 } \ No newline at end of file diff --git a/front/server/src/config.test.ts b/front/server/src/config.test.ts index 7463aba6..01a8a3d4 100644 --- a/front/server/src/config.test.ts +++ b/front/server/src/config.test.ts @@ -40,6 +40,7 @@ const defaultConfig: Config = { }, hosts: { default: { + cookie_domain: "openstream.fm", admin: { host: "admin.openstream.fm" }, api: { host: "api.openstream.fm" }, site: { host: "openstream.fm" }, @@ -87,6 +88,7 @@ public_key = "test_public_key" private_key = "test_private_key" [hosts.default] +cookie_domain = "openstream.fm" admin = { host = "admin.openstream.fm" } api = { host = "api.openstream.fm" } site = { host = "openstream.fm" } @@ -119,6 +121,7 @@ test("merge_env should merge environment variables with config", (t) => { OPENSTREAM_FRONT_PAYMENTS_CREDENTIALS_PRIVATE_KEY: "test_private_key_env", OPENSTREAM_FRONT_HOSTS: JSON.stringify({ "default": { + "cookie_domain": "openstream.fm", "admin": { "host": "admin.openstream.fm" }, "api": { "host": "api.openstream.fm" }, "site": { "host": "openstream.fm" }, @@ -161,6 +164,7 @@ test("merge_env should merge environment variables with config", (t) => { }, hosts: { default: { + cookie_domain: "openstream.fm", admin: { host: "admin.openstream.fm" }, api: { host: "api.openstream.fm" }, site: { host: "openstream.fm" }, @@ -223,6 +227,7 @@ test("load_from_string should load config from JSON string with missing properti OPENSTREAM_FRONT_PAYMENTS_CREDENTIALS_PRIVATE_KEY: "test_private_key", OPENSTREAM_FRONT_HOSTS: JSON.stringify({ "default": { + "cookie_domain": "openstream.fm", "admin": { "host": "admin.openstream.fm" }, "api": { "host": "api.openstream.fm" }, "site": { "host": "openstream.fm" }, @@ -263,6 +268,7 @@ test("load_from_string should load config from JSON string with missing properti OPENSTREAM_FRONT_PAYMENTS_CREDENTIALS_PRIVATE_KEY: "test_private_key", OPENSTREAM_FRONT_HOSTS: JSON.stringify({ "default": { + "cookie_domain": "openstream.fm", "admin": { "host": "admin.openstream.fm" }, "api": { "host": "api.openstream.fm" }, "site": { "host": "openstream.fm" }, @@ -292,6 +298,7 @@ test("load_from_string should load config from JSON string with missing properti invalid_key = "invalid_value" [hosts.default] + cookie_domain = "openstream.fm" site = { host = "openstream.fm" } admin = { host = "admin.openstream.fm" } api = { host = "api.openstream.fm" } @@ -340,6 +347,7 @@ test("load_from_string should load config from JSON string with missing properti port = 3000 [hosts.default] + cookie_domain = "openstream.fm" site = { host = "openstream.fm" } admin = { host = "admin.openstream.fm" } api = { host = "api.openstream.fm" } diff --git a/front/server/src/config.ts b/front/server/src/config.ts index e5723680..9c6cbe4c 100644 --- a/front/server/src/config.ts +++ b/front/server/src/config.ts @@ -48,6 +48,7 @@ export type Config = { } export type HostConfig = { + cookie_domain: string, site: { host: string } studio: { host: string } admin: { host: string } diff --git a/front/server/src/session.ts b/front/server/src/session.ts index 5c57f06c..114953d8 100644 --- a/front/server/src/session.ts +++ b/front/server/src/session.ts @@ -110,7 +110,7 @@ export const session = (mode: "studio" | "admin", config: Config, _logger: Logge const hosts = host(mode, config.hosts, req); - const domain = hosts.site.host; + const domain = hosts.cookie_domain; const cookie_name = `${config.session.cookie_name}-${hosts.id}`;