replace static env vars with dynamic ones

This commit is contained in:
Chris W 2023-10-16 22:59:39 -06:00
parent 48a090be5f
commit 6f74c3a789
6 changed files with 12 additions and 12 deletions

View File

@ -1,8 +1,8 @@
import { MongoClient } from 'mongodb'; import { MongoClient } from 'mongodb';
import { DB_URL } from '$env/static/private'; import { env } from '$env/dynamic/private';
import type PasteSchema from "./paste-schema"; import type PasteSchema from "./paste-schema";
const client = new MongoClient(DB_URL); const client = new MongoClient(env.DB_URL);
await client.connect(); await client.connect();
const db = client.db("paste69"); const db = client.db("paste69");

View File

@ -1,9 +1,9 @@
import { SENTRY_DSN } from '$env/static/private'; import { env } from '$env/dynamic/private';
import * as Sentry from '@sentry/node'; import * as Sentry from '@sentry/node';
import type { HandleServerError } from '@sveltejs/kit'; import type { HandleServerError } from '@sveltejs/kit';
Sentry.init({ Sentry.init({
dsn: SENTRY_DSN, dsn: env.SENTRY_DSN,
}); });
interface ServerError extends Error { interface ServerError extends Error {

View File

@ -1,7 +1,7 @@
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
import { pastes } from '$db/index'; import { pastes } from '$db/index';
import { SITE_URL } from '$env/static/private'; import { env } from '$env/dynamic/private';
export const load: PageLoad = async ({ params }) => { export const load: PageLoad = async ({ params }) => {
const [id, ext] = params.slug.split('.'); const [id, ext] = params.slug.split('.');
@ -15,7 +15,7 @@ export const load: PageLoad = async ({ params }) => {
// Build the response object // Build the response object
const response = { const response = {
id: paste.id, id: paste.id,
url: `${SITE_URL}/${id}.${paste.highlight}`, url: `${env.SITE_URL}/${id}.${paste.highlight}`,
contents: paste.contents, contents: paste.contents,
encrypted: paste.encrypted, encrypted: paste.encrypted,
highlight: ext || paste.highlight, highlight: ext || paste.highlight,

View File

@ -1,7 +1,7 @@
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
import { pastes } from '$db/index'; import { pastes } from '$db/index';
import { SITE_URL } from '$env/static/private'; import { env } from '$env/dynamic/private';
export const load: PageLoad = async ({ params }) => { export const load: PageLoad = async ({ params }) => {
const paste = await pastes.findOne({ id: params.slug }); const paste = await pastes.findOne({ id: params.slug });
@ -10,7 +10,7 @@ export const load: PageLoad = async ({ params }) => {
throw error(404, 'Paste not found'); throw error(404, 'Paste not found');
} }
const pasteUrl = `${SITE_URL}/${paste.id}.${paste.highlight}`; const pasteUrl = `${env.SITE_URL}/${paste.id}.${paste.highlight}`;
return { return {
pasteUrl, pasteUrl,

View File

@ -3,7 +3,7 @@ import { encrypt as doEncrypt } from "$utils/crypto";
import { error, json, type RequestHandler } from "@sveltejs/kit"; import { error, json, type RequestHandler } from "@sveltejs/kit";
import { generate } from 'random-words'; import { generate } from 'random-words';
import { pastes } from "$db/index"; import { pastes } from "$db/index";
import { SITE_URL } from "$env/static/private"; import { env } from "$env/dynamic/private";
import { extensionMap } from "$utils/languages"; import { extensionMap } from "$utils/languages";
export const POST: RequestHandler = async ({ request }) => { export const POST: RequestHandler = async ({ request }) => {
@ -36,7 +36,7 @@ export const POST: RequestHandler = async ({ request }) => {
const data = { const data = {
id, id,
url: `${SITE_URL}/${id}.${highlight}`, url: `${env.SITE_URL}/${id}.${highlight}`,
highlight, highlight,
encrypted: !!encrypt, encrypted: !!encrypt,
contents: pasteContents, contents: pasteContents,

View File

@ -1,5 +1,5 @@
import { pastes } from "$db/index"; 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"; import { error, type RequestHandler } from "@sveltejs/kit";
export const GET: RequestHandler = async ({ params }) => { 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. // Truncate each line to 80 characters, and pad the rest with spaces.
lines = lines.map(line => line.slice(0, 70).padEnd(70, ' ')); 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 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); const res = await fetch(url);