From ba92150607b63db16a1815d43254b6749ccdded9 Mon Sep 17 00:00:00 2001 From: khady Date: Tue, 10 Feb 2026 14:44:56 +0000 Subject: [PATCH 1/3] feat(env): add BASE_URL update server cookie path --- api/env.ts | 6 ++++++ api/server.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/env.ts b/api/env.ts index 9f78843..a5b90ad 100644 --- a/api/env.ts +++ b/api/env.ts @@ -128,6 +128,12 @@ const forAppEnv = * ``` */ export const PROD: EnvGetter = forAppEnv('prod') + +export const BASE_URL = PROD('BASE_URL', '/') +if (!BASE_URL.startsWith('/') || !BASE_URL.endsWith('/')) { + throw Error('incorrect BASE_URL: must start and end with /') +} + /** * TEST env getter * diff --git a/api/server.ts b/api/server.ts index 8110e19..1a4a39c 100644 --- a/api/server.ts +++ b/api/server.ts @@ -40,6 +40,7 @@ import { type RequestContext, runContext } from './context.ts' import { respond, ResponseError } from './response.ts' import { now } from '@01edu/time' import type { Awaitable } from '@01edu/types' +import { BASE_URL } from '@01edu/api/env' type Handler = (ctx: RequestContext) => Awaitable /** @@ -99,7 +100,7 @@ export const server = ( setCookie(res.headers, { name: 'trace', value: String(ctx.trace), - path: '/', + path: BASE_URL, secure: true, httpOnly: true, sameSite: 'Lax', From 5f48e010de827adf4567a211a3dffdce2538f3bd Mon Sep 17 00:00:00 2001 From: khady Date: Tue, 10 Feb 2026 14:49:00 +0000 Subject: [PATCH 2/3] feat: update version to 0.1.7 --- api/deno.json | 2 +- api/env.ts | 2 +- api/server.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/deno.json b/api/deno.json index 604b180..b93b346 100644 --- a/api/deno.json +++ b/api/deno.json @@ -4,7 +4,7 @@ "@std/http": "jsr:@std/http@^1.0.22" }, "name": "@01edu/api", - "version": "0.1.6", + "version": "0.1.7", "license": "MIT", "exports": { "./context": "./context.ts", diff --git a/api/env.ts b/api/env.ts index a5b90ad..18109b9 100644 --- a/api/env.ts +++ b/api/env.ts @@ -129,7 +129,7 @@ const forAppEnv = */ export const PROD: EnvGetter = forAppEnv('prod') -export const BASE_URL = PROD('BASE_URL', '/') +export const BASE_URL: string = PROD('BASE_URL', '/') if (!BASE_URL.startsWith('/') || !BASE_URL.endsWith('/')) { throw Error('incorrect BASE_URL: must start and end with /') } diff --git a/api/server.ts b/api/server.ts index 1a4a39c..78860a8 100644 --- a/api/server.ts +++ b/api/server.ts @@ -40,7 +40,7 @@ import { type RequestContext, runContext } from './context.ts' import { respond, ResponseError } from './response.ts' import { now } from '@01edu/time' import type { Awaitable } from '@01edu/types' -import { BASE_URL } from '@01edu/api/env' +import { BASE_URL } from './env.ts' type Handler = (ctx: RequestContext) => Awaitable /** From aac91a2b8d4f3a0bff394f3b68c1933bfc97e278 Mon Sep 17 00:00:00 2001 From: khady Date: Thu, 12 Feb 2026 13:06:55 +0000 Subject: [PATCH 3/3] feat(env): add doc for BASE_URL --- api/env.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/api/env.ts b/api/env.ts index 18109b9..4208392 100644 --- a/api/env.ts +++ b/api/env.ts @@ -129,6 +129,25 @@ const forAppEnv = */ export const PROD: EnvGetter = forAppEnv('prod') +/** + * + * The root for all relative URLs will be this BASE_URL, so it should start and end with a slash. + * If base URL is not set, it defaults to '/', which means the app is served at the root of the domain. + * If the current application is deployed at https://domain.com/tournament/, with + * will point to https://domain.com/tournament/dashboard + * + * @example + * ```ts + * import { BASE_URL } from '@01edu/api/env'; + * + * // for this example the 'index.html' file's `` tag is dynamically replaced during the build process to adapt to the deployment environment. + * const html = Deno.readTextFileSync(import.meta.dirname + '/dist/index.html') + .replace( + '', + ``, + ) + * ``` + */ export const BASE_URL: string = PROD('BASE_URL', '/') if (!BASE_URL.startsWith('/') || !BASE_URL.endsWith('/')) { throw Error('incorrect BASE_URL: must start and end with /')