97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import { MiddlewareConsumer, Module } from '@nestjs/common';
|
|
import { ConfigModule } from '@nestjs/config';
|
|
import { PassportModule } from '@nestjs/passport';
|
|
import * as dotenv from 'dotenv';
|
|
import fs from 'fs-extra';
|
|
import { WinstonModule, utilities as nestWinstonModuleUtilities } from 'nest-winston';
|
|
import * as winston from 'winston';
|
|
import { AiModule } from './ai/ai.module';
|
|
import { AppController } from './app.controller';
|
|
import { AppService } from './app.service';
|
|
import { AuthModule } from './auth/auth.module';
|
|
import { FileService } from './file/file.service';
|
|
import { GeoModule } from './geo/geo.module';
|
|
import { ImageModule } from './image/image.module';
|
|
import { ListingsModule } from './listings/listings.module';
|
|
import { LogController } from './log/log.controller';
|
|
import { LogModule } from './log/log.module';
|
|
|
|
import { JwtStrategy } from './jwt.strategy';
|
|
import { MailModule } from './mail/mail.module';
|
|
import { PaymentModule } from './payment/payment.module';
|
|
import { RequestDurationMiddleware } from './request-duration/request-duration.middleware';
|
|
import { SelectOptionsModule } from './select-options/select-options.module';
|
|
import { UserModule } from './user/user.module';
|
|
// const __filename = fileURLToPath(import.meta.url);
|
|
// const __dirname = path.dirname(__filename);
|
|
|
|
function loadEnvFiles() {
|
|
// Determine which additional env file to load
|
|
let envFilePath = '';
|
|
const host = process.env.HOST_NAME || '';
|
|
|
|
if (host.includes('localhost')) {
|
|
envFilePath = '.env.local';
|
|
} else if (host.includes('dev.bizmatch.net')) {
|
|
envFilePath = '.env.dev';
|
|
} else if (host.includes('www.bizmatch.net') || host.includes('bizmatch.net')) {
|
|
envFilePath = '.env.prod';
|
|
}
|
|
|
|
// Load the additional env file if it exists
|
|
if (fs.existsSync(envFilePath)) {
|
|
dotenv.config({ path: envFilePath });
|
|
console.log(`Loaded ${envFilePath} file`);
|
|
} else {
|
|
console.log(`No additional .env file found for HOST_NAME: ${host}`);
|
|
}
|
|
|
|
// Load the .env file
|
|
dotenv.config();
|
|
console.log('Loaded .env file');
|
|
// Output all loaded environment variables
|
|
console.log('Loaded environment variables:');
|
|
console.log(JSON.stringify(process.env, null, 2));
|
|
}
|
|
|
|
loadEnvFiles();
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({ isGlobal: true }),
|
|
MailModule,
|
|
AuthModule,
|
|
WinstonModule.forRoot({
|
|
transports: [
|
|
new winston.transports.Console({
|
|
format: winston.format.combine(
|
|
winston.format.timestamp(),
|
|
winston.format.ms(),
|
|
nestWinstonModuleUtilities.format.nestLike('Bizmatch', {
|
|
colors: true,
|
|
prettyPrint: true,
|
|
}),
|
|
),
|
|
}),
|
|
// other transports...
|
|
],
|
|
// other options
|
|
}),
|
|
GeoModule,
|
|
UserModule,
|
|
ListingsModule,
|
|
SelectOptionsModule,
|
|
ImageModule,
|
|
PassportModule,
|
|
AiModule,
|
|
LogModule,
|
|
PaymentModule,
|
|
],
|
|
controllers: [AppController, LogController],
|
|
providers: [AppService, FileService, JwtStrategy],
|
|
})
|
|
export class AppModule {
|
|
configure(consumer: MiddlewareConsumer) {
|
|
consumer.apply(RequestDurationMiddleware).forRoutes('*');
|
|
}
|
|
}
|