Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# Backend Environment Variables
# Copy this to .env and fill in your actual values

# Supabase Configuration (get from https://app.supabase.com → Project Settings → API)
# Supabase Configuration
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# HuggingFace API Token (optional - get from https://huggingface.co/settings/tokens)
# If not provided, crisis detection will use keyword-based fallback
# HuggingFace API Token (Optional)
HUGGINGFACE_API_TOKEN=hf_YourTokenHere
Comment on lines +1 to 7

Copilot AI Feb 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated .env.example file removes helpful documentation that was present in the original version, such as URLs where developers can obtain the required keys (e.g., "get from https://app.supabase.com → Project Settings → API" for Supabase configuration, "get from https://huggingface.co/settings/tokens" for HuggingFace). Consider restoring these comments to improve the developer experience, especially for new contributors who may not know where to find these credentials.

Copilot uses AI. Check for mistakes.

# Frontend URL (for CORS whitelist)
FRONTEND_URL=http://localhost:3000

# Server Configuration
PORT=3001
FRONTEND_URL=http://localhost:3000

# Rate Limiting (optional - defaults shown)
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
12 changes: 11 additions & 1 deletion backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"start": "node dist/index.js",
"setup-db": "ts-node src/scripts/setupDatabase.ts"
},
"keywords": ["mental-health", "websocket", "express", "crisis-detection"],
"keywords": [
"mental-health",
"websocket",
"express",
"crisis-detection"
],
"author": "OpenMindWell Contributors",
"license": "MIT",
"dependencies": {
Expand All @@ -19,7 +24,8 @@
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"helmet": "^7.1.0",
"ws": "^8.16.0"
"ws": "^8.16.0",
"zod": "^4.3.6"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand Down
32 changes: 32 additions & 0 deletions backend/src/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { z } from 'zod';
import dotenv from 'dotenv';

dotenv.config();

const envSchema = z.object({
// Supabase Configuration
SUPABASE_URL: z.string().url(),
SUPABASE_ANON_KEY: z.string().min(1),
SUPABASE_SERVICE_ROLE_KEY: z.string().min(1),

// HuggingFace API Token (Optional)
HUGGINGFACE_API_TOKEN: z.string().optional(),

// Server Configuration
FRONTEND_URL: z.string().url().default('http://localhost:3000'),
PORT: z.coerce.number().default(3001),

// Rate Limiting
RATE_LIMIT_WINDOW_MS: z.coerce.number().default(900000),
RATE_LIMIT_MAX_REQUESTS: z.coerce.number().default(100),
});

const _env = envSchema.safeParse(process.env);

if (!_env.success) {
console.error('Invalid environment variables:');
console.error(JSON.stringify(_env.error.format(), null, 4));
process.exit(1);
}

export const env = _env.data;
58 changes: 10 additions & 48 deletions backend/src/config/index.ts
Comment thread
ayushHardeniya marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
import dotenv from 'dotenv';
import { env } from './env';

dotenv.config();

interface Config {
const config = {
supabase: {
url: string;
anonKey: string;
serviceRoleKey: string;
};
huggingface: {
apiToken?: string;
};
server: {
port: number;
frontendUrl: string;
};
rateLimit: {
windowMs: number;
maxRequests: number;
};
}

const config: Config = {
supabase: {
url: process.env.SUPABASE_URL || '',
anonKey: process.env.SUPABASE_ANON_KEY || '',
serviceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY || '',
url: env.SUPABASE_URL,
anonKey: env.SUPABASE_ANON_KEY,
serviceRoleKey: env.SUPABASE_SERVICE_ROLE_KEY,
},
huggingface: {
apiToken: process.env.HUGGINGFACE_API_TOKEN,
apiToken: env.HUGGINGFACE_API_TOKEN,
},
server: {
port: parseInt(process.env.PORT || '3001', 10),
frontendUrl: process.env.FRONTEND_URL || 'http://localhost:3000',
port: env.PORT,
frontendUrl: env.FRONTEND_URL,
},
rateLimit: {
windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS || '900000', 10),
maxRequests: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS || '100', 10),
windowMs: env.RATE_LIMIT_WINDOW_MS,
maxRequests: env.RATE_LIMIT_MAX_REQUESTS,
},
};

// Validation
const requiredEnvVars = [
'SUPABASE_URL',
'SUPABASE_ANON_KEY',
'SUPABASE_SERVICE_ROLE_KEY',
'FRONTEND_URL',
];

const missingVars = requiredEnvVars.filter((varName) => !process.env[varName]);

if (missingVars.length > 0) {
throw new Error(
`Missing required environment variables: ${missingVars.join(', ')}\n` +
'Please check your .env file and ensure all required variables are set.'
);
}

export default config;