From 6f74c3a789a90cd890e4c946e3404e5c87f916b5 Mon Sep 17 00:00:00 2001 From: Chris W Date: Mon, 16 Oct 2023 22:59:39 -0600 Subject: [PATCH] replace static env vars with dynamic ones --- src/db/index.ts | 4 ++-- src/hooks.server.ts | 4 ++-- src/routes/[slug]/+page.server.ts | 4 ++-- src/routes/[slug]/created/+page.server.ts | 4 ++-- src/routes/api/pastes/+server.ts | 4 ++-- src/routes/images/paste/[id]/+server.ts | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/db/index.ts b/src/db/index.ts index 6e38406..c82439c 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,8 +1,8 @@ import { MongoClient } from 'mongodb'; -import { DB_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; import type PasteSchema from "./paste-schema"; -const client = new MongoClient(DB_URL); +const client = new MongoClient(env.DB_URL); await client.connect(); const db = client.db("paste69"); diff --git a/src/hooks.server.ts b/src/hooks.server.ts index adc2cc7..841b8f2 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,9 +1,9 @@ -import { SENTRY_DSN } from '$env/static/private'; +import { env } from '$env/dynamic/private'; import * as Sentry from '@sentry/node'; import type { HandleServerError } from '@sveltejs/kit'; Sentry.init({ - dsn: SENTRY_DSN, + dsn: env.SENTRY_DSN, }); interface ServerError extends Error { diff --git a/src/routes/[slug]/+page.server.ts b/src/routes/[slug]/+page.server.ts index f38d832..115ca62 100644 --- a/src/routes/[slug]/+page.server.ts +++ b/src/routes/[slug]/+page.server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit'; import type { PageLoad } from './$types'; import { pastes } from '$db/index'; -import { SITE_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; export const load: PageLoad = async ({ params }) => { const [id, ext] = params.slug.split('.'); @@ -15,7 +15,7 @@ export const load: PageLoad = async ({ params }) => { // Build the response object const response = { id: paste.id, - url: `${SITE_URL}/${id}.${paste.highlight}`, + url: `${env.SITE_URL}/${id}.${paste.highlight}`, contents: paste.contents, encrypted: paste.encrypted, highlight: ext || paste.highlight, diff --git a/src/routes/[slug]/created/+page.server.ts b/src/routes/[slug]/created/+page.server.ts index 3885cd4..138719b 100644 --- a/src/routes/[slug]/created/+page.server.ts +++ b/src/routes/[slug]/created/+page.server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit'; import type { PageLoad } from './$types'; import { pastes } from '$db/index'; -import { SITE_URL } from '$env/static/private'; +import { env } from '$env/dynamic/private'; export const load: PageLoad = async ({ params }) => { const paste = await pastes.findOne({ id: params.slug }); @@ -10,7 +10,7 @@ export const load: PageLoad = async ({ params }) => { throw error(404, 'Paste not found'); } - const pasteUrl = `${SITE_URL}/${paste.id}.${paste.highlight}`; + const pasteUrl = `${env.SITE_URL}/${paste.id}.${paste.highlight}`; return { pasteUrl, diff --git a/src/routes/api/pastes/+server.ts b/src/routes/api/pastes/+server.ts index 30c5b71..cb3cec1 100644 --- a/src/routes/api/pastes/+server.ts +++ b/src/routes/api/pastes/+server.ts @@ -3,7 +3,7 @@ import { encrypt as doEncrypt } from "$utils/crypto"; import { error, json, type RequestHandler } from "@sveltejs/kit"; import { generate } from 'random-words'; import { pastes } from "$db/index"; -import { SITE_URL } from "$env/static/private"; +import { env } from "$env/dynamic/private"; import { extensionMap } from "$utils/languages"; export const POST: RequestHandler = async ({ request }) => { @@ -36,7 +36,7 @@ export const POST: RequestHandler = async ({ request }) => { const data = { id, - url: `${SITE_URL}/${id}.${highlight}`, + url: `${env.SITE_URL}/${id}.${highlight}`, highlight, encrypted: !!encrypt, contents: pasteContents, diff --git a/src/routes/images/paste/[id]/+server.ts b/src/routes/images/paste/[id]/+server.ts index adc5444..8436116 100644 --- a/src/routes/images/paste/[id]/+server.ts +++ b/src/routes/images/paste/[id]/+server.ts @@ -1,5 +1,5 @@ import { pastes } from "$db/index"; -import { SITE_URL } from "$env/static/private"; +import { env } from "$env/dynamic/private"; import { error, type RequestHandler } from "@sveltejs/kit"; export const GET: RequestHandler = async ({ params }) => { @@ -27,7 +27,7 @@ export const GET: RequestHandler = async ({ params }) => { // Truncate each line to 80 characters, and pad the rest with spaces. lines = lines.map(line => line.slice(0, 70).padEnd(70, ' ')); - const title = `${SITE_URL}/${id}.${paste.highlight}`; + const title = `${env.SITE_URL}/${id}.${paste.highlight}`; const url = `https://inkify.0x45.st/generate?code=${encodeURIComponent(lines.join('\n'))}&window_title=${encodeURIComponent(title)}&language=${encodeURIComponent(paste.highlight)}&pad_horiz=5&pad_vert=5`; const res = await fetch(url);