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 9f78843..18109b9 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: string = 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..78860a8 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 './env.ts' 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',