Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(server): immich app env #13169

Merged
merged 1 commit into from
Oct 3, 2024
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
9 changes: 7 additions & 2 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export class ApiModule implements OnModuleInit, OnModuleDestroy {
private moduleRef: ModuleRef,
@Inject(IEventRepository) private eventRepository: IEventRepository,
@Inject(ILoggerRepository) private logger: ILoggerRepository,
) {}
) {
logger.setAppName('Api');
}

async onModuleInit() {
const items = setupEventHandlers(this.moduleRef);
Expand Down Expand Up @@ -95,7 +97,10 @@ export class MicroservicesModule implements OnModuleInit, OnModuleDestroy {
constructor(
private moduleRef: ModuleRef,
@Inject(IEventRepository) private eventRepository: IEventRepository,
) {}
@Inject(ILoggerRepository) logger: ILoggerRepository,
) {
logger.setAppName('Microservices');
}

async onModuleInit() {
setupEventHandlers(this.moduleRef);
Expand Down
1 change: 0 additions & 1 deletion server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const serverVersion = new SemVer(version);
export const AUDIT_LOG_MAX_DURATION = Duration.fromObject({ days: 100 });
export const ONE_HOUR = Duration.fromObject({ hours: 1 });

export const envName = (process.env.IMMICH_ENV || 'production').toUpperCase();
export const APP_MEDIA_LOCATION = process.env.IMMICH_MEDIA_LOCATION || './upload';
const HOST_SERVER_PORT = process.env.IMMICH_PORT || '2283';
export const DEFAULT_EXTERNAL_DOMAIN = 'http://localhost:' + HOST_SERVER_PORT;
Expand Down
5 changes: 2 additions & 3 deletions server/src/workers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cookieParser from 'cookie-parser';
import { existsSync } from 'node:fs';
import sirv from 'sirv';
import { ApiModule } from 'src/app.module';
import { envName, excludePaths, resourcePaths, serverVersion } from 'src/constants';
import { excludePaths, resourcePaths, serverVersion } from 'src/constants';
import { ImmichEnvironment } from 'src/enum';
import { IConfigRepository } from 'src/interfaces/config.interface';
import { ILoggerRepository } from 'src/interfaces/logger.interface';
Expand Down Expand Up @@ -39,7 +39,6 @@ async function bootstrap() {
const { environment, port } = configRepository.getEnv();
const isDev = environment === ImmichEnvironment.DEVELOPMENT;

logger.setAppName('Api');
logger.setContext('Bootstrap');
app.useLogger(logger);
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal', ...trustedProxies]);
Expand Down Expand Up @@ -75,7 +74,7 @@ async function bootstrap() {
const server = await (host ? app.listen(port, host) : app.listen(port));
server.requestTimeout = 30 * 60 * 1000;

logger.log(`Immich Server is listening on ${await app.getUrl()} [v${serverVersion}] [${envName}] `);
logger.log(`Immich Server is listening on ${await app.getUrl()} [v${serverVersion}] [${environment}] `);
}

bootstrap().catch((error) => {
Expand Down
7 changes: 5 additions & 2 deletions server/src/workers/microservices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { isMainThread } from 'node:worker_threads';
import { MicroservicesModule } from 'src/app.module';
import { envName, serverVersion } from 'src/constants';
import { serverVersion } from 'src/constants';
import { IConfigRepository } from 'src/interfaces/config.interface';
import { ILoggerRepository } from 'src/interfaces/logger.interface';
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
import { isStartUpError } from 'src/utils/events';
Expand All @@ -21,7 +22,9 @@ export async function bootstrap() {

await app.listen(0);

logger.log(`Immich Microservices is running [v${serverVersion}] [${envName}] `);
const configRepository = app.get<IConfigRepository>(IConfigRepository);
const { environment } = configRepository.getEnv();
logger.log(`Immich Microservices is running [v${serverVersion}] [${environment}] `);
}

if (!isMainThread) {
Expand Down
Loading