immich/server/src/immich/main.ts

39 lines
1.4 KiB
TypeScript
Raw Normal View History

import { envName, getLogLevels, isDev, serverVersion } from '@app/domain';
2023-12-08 11:15:46 -05:00
import { RedisIoAdapter, enablePrefilter } from '@app/infra';
import { Logger } from '@nestjs/common';
2022-02-03 10:06:44 -06:00
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { json } from 'body-parser';
import cookieParser from 'cookie-parser';
2022-02-03 10:06:44 -06:00
import { AppModule } from './app.module';
import { indexFallback, useSwagger } from './app.utils';
2022-02-03 10:06:44 -06:00
const logger = new Logger('ImmichServer');
const port = Number(process.env.SERVER_PORT) || 3001;
export async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule, { logger: getLogLevels() });
2022-02-03 10:06:44 -06:00
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
app.set('etag', 'strong');
app.use(cookieParser());
app.use(json({ limit: '10mb' }));
2023-06-01 22:12:22 -04:00
if (isDev) {
app.enableCors();
}
2023-03-31 10:36:08 -04:00
app.useWebSocketAdapter(new RedisIoAdapter(app));
2023-06-01 22:12:22 -04:00
useSwagger(app, isDev);
const excludePaths = ['/.well-known/immich', '/custom.css'];
app.setGlobalPrefix('api', { exclude: excludePaths });
app.useStaticAssets('www');
app.use(indexFallback(excludePaths));
2023-12-08 11:15:46 -05:00
await enablePrefilter();
const server = await app.listen(port);
server.requestTimeout = 30 * 60 * 1000;
logger.log(`Immich Server is listening on ${await app.getUrl()} [v${serverVersion}] [${envName}] `);
2022-02-03 10:06:44 -06:00
}