Skip to content

Commit

Permalink
feat: add customizable cookie_domain to front hosts (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiroaisen authored Jul 3, 2023
2 parents b418a45 + 535512d commit 627ec29
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 79 deletions.
42 changes: 1 addition & 41 deletions front/server/openstream-front.sample.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -90,54 +90,14 @@

"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 }
},


"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 }
}
}
}
39 changes: 2 additions & 37 deletions front/server/openstream-front.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
source = { host = "source.openstream.fm", port = 8000 }
8 changes: 8 additions & 0 deletions front/server/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions front/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type Config = {
}

export type HostConfig = {
cookie_domain: string,
site: { host: string }
studio: { host: string }
admin: { host: string }
Expand Down
2 changes: 1 addition & 1 deletion front/server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Expand Down

0 comments on commit 627ec29

Please sign in to comment.