detached 293f7fe

fix(cloudflare): replace process.env with SvelteKit env modules

commit
293f7fed042ca1bea935d2186030d3087e3fec51
author
bnema · · 2026-01-18 22:08 UTC
parent
13a549c
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +11 -9
M src/lib/api/session.cookie.ts +9 -7
@@ -1,4 +1,6 @@
11 import type { Cookies } from '@sveltejs/kit';
2+import { dev } from '$app/environment';
3+import { env } from '$env/dynamic/private';
24 import { createLogger } from '$lib/utils/logger.server';
35
46 const log = createLogger('session-cookie');
@@ -6,19 +8,19 @@ const log = createLogger('session-cookie');
68 // Helper function to determine cookie domain
79 function getCookieDomain(): string | undefined {
810 // Allow explicit override via environment variable
9- const envDomain = process.env.COOKIE_DOMAIN;
11+ const envDomain = env.COOKIE_DOMAIN;
1012 if (envDomain) {
1113 log.debug('Using COOKIE_DOMAIN from environment:', { domain: envDomain });
1214 return envDomain;
1315 }
1416
15- if (process.env.NODE_ENV === 'production') {
17+ if (!dev) {
1618 // Check for Cloudflare Pages domain
17- if (process.env.CF_PAGES_URL) {
18- const url = process.env.CF_PAGES_URL;
19+ if (env.CF_PAGES_URL) {
20+ const url = env.CF_PAGES_URL;
1921 log.debug('Cloudflare Pages URL:', { url });
2022 // For preview deployments, use host-only cookie
21- if (process.env.CF_PAGES_BRANCH !== 'main') {
23+ if (env.CF_PAGES_BRANCH !== 'main') {
2224 return undefined;
2325 }
2426 // For production on Cloudflare Pages, use host-only cookie (safest default)
@@ -44,7 +46,7 @@ export function setSessionTokenCookie(
4446 cookies.set('session', token, {
4547 httpOnly: true,
4648 sameSite: 'lax',
47- secure: process.env.NODE_ENV === 'production',
49+ secure: !dev,
4850 domain,
4951 expires: new Date(expiresAt),
5052 path: '/'
@@ -60,7 +62,7 @@ export function deleteSessionTokenCookie({ cookies }: { cookies: Cookies }): voi
6062 cookies.set('session', '', {
6163 httpOnly: true,
6264 sameSite: 'lax',
63- secure: process.env.NODE_ENV === 'production',
65+ secure: !dev,
6466 domain,
6567 maxAge: 0,
6668 path: '/'
@@ -1,4 +1,6 @@
1 import type { Cookies } from '@sveltejs/kit';1 import type { Cookies } from '@sveltejs/kit';
2+import { dev } from '$app/environment';
3+import { env } from '$env/dynamic/private';
2 import { createLogger } from '$lib/utils/logger.server';4 import { createLogger } from '$lib/utils/logger.server';
3 5
4 const log = createLogger('session-cookie');6 const log = createLogger('session-cookie');
@@ -6,19 +8,19 @@ const log = createLogger('session-cookie');
6 // Helper function to determine cookie domain8 // Helper function to determine cookie domain
7 function getCookieDomain(): string | undefined {9 function getCookieDomain(): string | undefined {
8 // Allow explicit override via environment variable10 // Allow explicit override via environment variable
9- const envDomain = process.env.COOKIE_DOMAIN;11+ const envDomain = env.COOKIE_DOMAIN;
10 if (envDomain) {12 if (envDomain) {
11 log.debug('Using COOKIE_DOMAIN from environment:', { domain: envDomain });13 log.debug('Using COOKIE_DOMAIN from environment:', { domain: envDomain });
12 return envDomain;14 return envDomain;
13 }15 }
14 16
15- if (process.env.NODE_ENV === 'production') {17+ if (!dev) {
16 // Check for Cloudflare Pages domain18 // Check for Cloudflare Pages domain
17- if (process.env.CF_PAGES_URL) {19+ if (env.CF_PAGES_URL) {
18- const url = process.env.CF_PAGES_URL;20+ const url = env.CF_PAGES_URL;
19 log.debug('Cloudflare Pages URL:', { url });21 log.debug('Cloudflare Pages URL:', { url });
20 // For preview deployments, use host-only cookie22 // For preview deployments, use host-only cookie
21- if (process.env.CF_PAGES_BRANCH !== 'main') {23+ if (env.CF_PAGES_BRANCH !== 'main') {
22 return undefined;24 return undefined;
23 }25 }
24 // For production on Cloudflare Pages, use host-only cookie (safest default)26 // For production on Cloudflare Pages, use host-only cookie (safest default)
@@ -44,7 +46,7 @@ export function setSessionTokenCookie(
44 cookies.set('session', token, {46 cookies.set('session', token, {
45 httpOnly: true,47 httpOnly: true,
46 sameSite: 'lax',48 sameSite: 'lax',
47- secure: process.env.NODE_ENV === 'production',49+ secure: !dev,
48 domain,50 domain,
49 expires: new Date(expiresAt),51 expires: new Date(expiresAt),
50 path: '/'52 path: '/'
@@ -60,7 +62,7 @@ export function deleteSessionTokenCookie({ cookies }: { cookies: Cookies }): voi
60 cookies.set('session', '', {62 cookies.set('session', '', {
61 httpOnly: true,63 httpOnly: true,
62 sameSite: 'lax',64 sameSite: 'lax',
63- secure: process.env.NODE_ENV === 'production',65+ secure: !dev,
64 domain,66 domain,
65 maxAge: 0,67 maxAge: 0,
66 path: '/'68 path: '/'
M src/lib/utils/turnstile.server.ts +2 -2
@@ -1,8 +1,8 @@
11 import { TURNSTILE_SECRET_KEY } from '$env/static/private';
2+import { dev } from '$app/environment';
23 import { createLogger } from './logger.server';
34
45 const log = createLogger('turnstile');
5-const isDev = process.env.NODE_ENV === 'development';
66
77 interface TurnstileVerifyResponse {
88 success: boolean;
@@ -15,7 +15,7 @@ interface TurnstileVerifyResponse {
1515
1616 export async function validateTurnstileToken(token: string, remoteip?: string): Promise<boolean> {
1717 // Always return true in development mode
18- if (isDev) {
18+ if (dev) {
1919 log.debug('Development mode: bypassing Turnstile validation');
2020 return true;
2121 }
@@ -1,8 +1,8 @@
1 import { TURNSTILE_SECRET_KEY } from '$env/static/private';1 import { TURNSTILE_SECRET_KEY } from '$env/static/private';
2+import { dev } from '$app/environment';
2 import { createLogger } from './logger.server';3 import { createLogger } from './logger.server';
3 4
4 const log = createLogger('turnstile');5 const log = createLogger('turnstile');
5-const isDev = process.env.NODE_ENV === 'development';
6 6
7 interface TurnstileVerifyResponse {7 interface TurnstileVerifyResponse {
8 success: boolean;8 success: boolean;
@@ -15,7 +15,7 @@ interface TurnstileVerifyResponse {
15 15
16 export async function validateTurnstileToken(token: string, remoteip?: string): Promise<boolean> {16 export async function validateTurnstileToken(token: string, remoteip?: string): Promise<boolean> {
17 // Always return true in development mode17 // Always return true in development mode
18- if (isDev) {18+ if (dev) {
19 log.debug('Development mode: bypassing Turnstile validation');19 log.debug('Development mode: bypassing Turnstile validation');
20 return true;20 return true;
21 }21 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 9

↑↓ moveenter openesc close