work on proxy
This commit is contained in:
parent
d67d07cba6
commit
2f070d73f9
6 changed files with 73 additions and 86 deletions
|
|
@ -29,7 +29,7 @@ export enum Environment {
|
|||
*/
|
||||
export function loadEnvVariables(envOverride?: string): void {
|
||||
const env = envOverride || process.env.NODE_ENV || 'development';
|
||||
|
||||
console.log(`Current environment: ${env}`);
|
||||
// Order of loading:
|
||||
// 1. .env (base environment variables)
|
||||
// 2. .env.{environment} (environment-specific variables)
|
||||
|
|
@ -51,7 +51,6 @@ export function loadEnvVariables(envOverride?: string): void {
|
|||
*/
|
||||
export function getEnvironment(): Environment {
|
||||
const env = process.env.NODE_ENV?.toLowerCase() || 'development';
|
||||
|
||||
switch (env) {
|
||||
case 'development':
|
||||
return Environment.Development;
|
||||
|
|
@ -64,5 +63,6 @@ export function getEnvironment(): Environment {
|
|||
return Environment.Production;
|
||||
default:
|
||||
return Environment.Development;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,51 @@
|
|||
*/
|
||||
import { z } from 'zod';
|
||||
import { config } from 'dotenv';
|
||||
import { join } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
// Function to find and load environment variables
|
||||
function loadEnvFiles() {
|
||||
const cwd = process.cwd();
|
||||
const possiblePaths = [
|
||||
// Current working directory
|
||||
join(cwd, '.env'),
|
||||
join(cwd, '.env.local'),
|
||||
// Root of the workspace (common pattern)
|
||||
join(cwd, '../../.env'),
|
||||
join(cwd, '../../../.env'),
|
||||
// Config library directory
|
||||
join(__dirname, '../.env'),
|
||||
join(__dirname, '../../.env'),
|
||||
join(__dirname, '../../../.env'),
|
||||
];
|
||||
|
||||
// Try to load each possible .env file
|
||||
for (const envPath of possiblePaths) {
|
||||
if (existsSync(envPath)) {
|
||||
console.log(`📄 Loading environment from: ${envPath}`);
|
||||
config({ path: envPath });
|
||||
break; // Use the first .env file found
|
||||
}
|
||||
}
|
||||
|
||||
// Also try to load environment-specific files
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
const envSpecificPaths = [
|
||||
join(cwd, `.env.${environment}`),
|
||||
join(cwd, `.env.${environment}.local`),
|
||||
];
|
||||
|
||||
for (const envPath of envSpecificPaths) {
|
||||
if (existsSync(envPath)) {
|
||||
console.log(`📄 Loading ${environment} environment from: ${envPath}`);
|
||||
config({ path: envPath, override: false }); // Don't override existing vars
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load environment variables
|
||||
config();
|
||||
loadEnvFiles();
|
||||
|
||||
/**
|
||||
* Creates a Zod schema for environment variable validation
|
||||
|
|
@ -34,6 +76,18 @@ export function validateEnv<T extends z.ZodRawShape>(
|
|||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually load environment variables from a specific path
|
||||
*/
|
||||
export function loadEnv(path?: string) {
|
||||
if (path) {
|
||||
console.log(`📄 Manually loading environment from: ${path}`);
|
||||
config({ path });
|
||||
} else {
|
||||
loadEnvFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper functions for common validation patterns
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export class HttpClient {
|
|||
async request<T = any>(config: RequestConfig): Promise<HttpResponse<T>> {
|
||||
const finalConfig = this.mergeConfig(config);
|
||||
const startTime = Date.now();
|
||||
|
||||
|
||||
this.logger?.debug('Making HTTP request', {
|
||||
method: finalConfig.method,
|
||||
url: finalConfig.url,
|
||||
|
|
@ -75,11 +75,10 @@ export class HttpClient {
|
|||
|
||||
/**
|
||||
* Execute request with timeout handling - no race conditions
|
||||
*/
|
||||
private async executeRequest<T>(config: RequestConfig): Promise<HttpResponse<T>> {
|
||||
*/ private async executeRequest<T>(config: RequestConfig): Promise<HttpResponse<T>> {
|
||||
const timeout = config.timeout ?? this.config.timeout ?? 30000;
|
||||
const controller = new AbortController();
|
||||
|
||||
|
||||
// Set up timeout
|
||||
const timeoutId = setTimeout(() => {
|
||||
controller.abort();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import type { LogLevel, LogContext, LogMetadata } from './types';
|
|||
|
||||
// Simple cache for logger instances
|
||||
const loggerCache = new Map<string, pino.Logger>();
|
||||
|
||||
console.log('Logger cache initialized: ', loggingConfig.LOG_LEVEL);
|
||||
/**
|
||||
* Create transport configuration
|
||||
*/
|
||||
|
|
@ -25,7 +25,7 @@ function createTransports(serviceName: string): any {
|
|||
if (loggingConfig.LOG_CONSOLE) {
|
||||
targets.push({
|
||||
target: 'pino-pretty',
|
||||
level: 'error', // Only show errors on console
|
||||
level: loggingConfig.LOG_LEVEL, // Only show errors on console
|
||||
options: {
|
||||
colorize: true,
|
||||
translateTime: 'yyyy-mm-dd HH:MM:ss.l',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue