Add bun.lockb file and update docker-compose.yml to remove sensitive environment variables. Refactor package.json to reorganize dependencies and add Bun types. Modify tsconfig.json to include Bun types. Update Redis client implementation in redis.ts for improved error handling and connection management.

This commit is contained in:
Luke Hagar
2025-10-20 23:45:50 -05:00
parent 4239bbaaa3
commit 38aa9ae169
6 changed files with 10 additions and 23 deletions

BIN
bun.lockb Executable file

Binary file not shown.

View File

@@ -40,8 +40,6 @@ services:
condition: service_healthy condition: service_healthy
environment: environment:
NODE_ENV: production NODE_ENV: production
SERVICE_PASSWORD_POSTGRES: ${POSTGRES_PASSWORD}
SERVICE_PASSWORD_REDIS: ${REDIS_PASSWORD}
DATABASE_URL: postgresql://pypistats:${POSTGRES_PASSWORD}@db:5432/pypistats?schema=public DATABASE_URL: postgresql://pypistats:${POSTGRES_PASSWORD}@db:5432/pypistats?schema=public
REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379 REDIS_URL: redis://:${REDIS_PASSWORD}@redis:6379
GOOGLE_APPLICATION_CREDENTIALS_BASE64: ${GOOGLE_APPLICATION_CREDENTIALS_BASE64} GOOGLE_APPLICATION_CREDENTIALS_BASE64: ${GOOGLE_APPLICATION_CREDENTIALS_BASE64}

View File

@@ -17,7 +17,7 @@
"db:migrate": "prisma migrate dev", "db:migrate": "prisma migrate dev",
"db:deploy": "prisma migrate deploy" "db:deploy": "prisma migrate deploy"
}, },
"dependencies": { "devDependencies": {
"@google-cloud/bigquery": "^8.1.1", "@google-cloud/bigquery": "^8.1.1",
"@prisma/client": "^6.15.0", "@prisma/client": "^6.15.0",
"@sveltejs/adapter-node": "^5.3.1", "@sveltejs/adapter-node": "^5.3.1",
@@ -26,9 +26,7 @@
"chart.js": "^4.5.0", "chart.js": "^4.5.0",
"chartjs-node-canvas": "^5.0.0", "chartjs-node-canvas": "^5.0.0",
"node-cron": "^4.2.1", "node-cron": "^4.2.1",
"redis": "^5.8.2" "redis": "^5.8.2",
},
"devDependencies": {
"@plausible-analytics/tracker": "^0.4.0", "@plausible-analytics/tracker": "^0.4.0",
"@sveltejs/adapter-auto": "^6.1.0", "@sveltejs/adapter-auto": "^6.1.0",
"@sveltejs/kit": "^2.37.0", "@sveltejs/kit": "^2.37.0",
@@ -36,6 +34,7 @@
"@tailwindcss/forms": "^0.5.10", "@tailwindcss/forms": "^0.5.10",
"@tailwindcss/typography": "^0.5.16", "@tailwindcss/typography": "^0.5.16",
"@tailwindcss/vite": "^4.1.12", "@tailwindcss/vite": "^4.1.12",
"@types/bun": "^1.3.0",
"mdsvex": "^0.12.6", "mdsvex": "^0.12.6",
"prettier": "^3.6.2", "prettier": "^3.6.2",
"prettier-plugin-svelte": "^3.4.0", "prettier-plugin-svelte": "^3.4.0",

View File

@@ -1,9 +1,4 @@
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
const globalForPrisma = globalThis as unknown as { export const prisma = new PrismaClient();
prisma: PrismaClient | undefined;
};
export const prisma = globalForPrisma.prisma ?? new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

View File

@@ -1,3 +1,4 @@
import { env } from '$env/dynamic/private';
import { createClient } from 'redis'; import { createClient } from 'redis';
// Redis client instance // Redis client instance
@@ -6,14 +7,7 @@ let isConnecting = false;
let isDisconnecting = false; let isDisconnecting = false;
export function getRedisClient() { export function getRedisClient() {
const redisUrl = process.env.REDIS_URL; const redisUrl = env.REDIS_URL;
// Skip connecting if no REDIS_URL is provided (e.g., during build)
if (!redisUrl) {
if (typeof process !== 'undefined') {
console.warn('Redis disabled: REDIS_URL not set');
}
return null;
}
if (!redisClient && !isConnecting) { if (!redisClient && !isConnecting) {
isConnecting = true; isConnecting = true;
@@ -21,7 +15,7 @@ export function getRedisClient() {
url: redisUrl, url: redisUrl,
}); });
redisClient.on('error', (err) => { redisClient.on('error', (err: any) => {
console.error('Redis Client Error:', err); console.error('Redis Client Error:', err);
}); });
@@ -76,7 +70,7 @@ export async function forceDisconnectRedis(): Promise<void> {
isDisconnecting = true; isDisconnecting = true;
try { try {
console.log('Force disconnecting Redis client...'); console.log('Force disconnecting Redis client...');
await redisClient.disconnect(); await redisClient.destroy();
console.log('Redis client force disconnected'); console.log('Redis client force disconnected');
} catch (error) { } catch (error) {
console.error('Error force disconnecting Redis client:', error); console.error('Error force disconnecting Redis client:', error);

View File

@@ -9,7 +9,8 @@
"skipLibCheck": true, "skipLibCheck": true,
"sourceMap": true, "sourceMap": true,
"strict": true, "strict": true,
"moduleResolution": "bundler" "moduleResolution": "bundler",
"types": ["bun"]
} }
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files