2023-10-24 17:05:42 +02:00
|
|
|
import { envName, getLogLevels, isDev, serverVersion } from '@app/domain';
|
2023-12-08 11:15:46 -05:00
|
|
|
import { RedisIoAdapter, enablePrefilter } from '@app/infra';
|
2022-03-28 15:21:15 -05:00
|
|
|
import { Logger } from '@nestjs/common';
|
2022-02-03 10:06:44 -06:00
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
2023-05-20 22:39:12 -04:00
|
|
|
import { json } from 'body-parser';
|
2022-07-18 14:14:25 -05:00
|
|
|
import cookieParser from 'cookie-parser';
|
2022-02-03 10:06:44 -06:00
|
|
|
import { AppModule } from './app.module';
|
2023-11-17 23:13:36 -05:00
|
|
|
import { indexFallback, useSwagger } from './app.utils';
|
2022-02-03 10:06:44 -06:00
|
|
|
|
2022-12-08 10:53:18 -05:00
|
|
|
const logger = new Logger('ImmichServer');
|
2023-06-07 10:56:08 -04:00
|
|
|
const port = Number(process.env.SERVER_PORT) || 3001;
|
2022-12-08 10:53:18 -05:00
|
|
|
|
2023-06-08 11:01:07 -04:00
|
|
|
export async function bootstrap() {
|
2023-06-07 10:56:08 -04:00
|
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, { logger: getLogLevels() });
|
2022-02-03 10:06:44 -06:00
|
|
|
|
2023-03-22 21:46:30 +01:00
|
|
|
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
2022-11-29 22:45:47 +01:00
|
|
|
app.set('etag', 'strong');
|
2022-07-18 14:14:25 -05:00
|
|
|
app.use(cookieParser());
|
2022-11-08 10:24:49 -05:00
|
|
|
app.use(json({ limit: '10mb' }));
|
2023-06-01 22:12:22 -04:00
|
|
|
if (isDev) {
|
2022-06-24 04:18:50 +01:00
|
|
|
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);
|
2023-01-20 11:35:55 -05:00
|
|
|
|
2023-11-17 23:13:36 -05:00
|
|
|
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();
|
|
|
|
|
|
2023-06-15 03:35:54 +01:00
|
|
|
const server = await app.listen(port);
|
2023-06-15 14:21:31 +01:00
|
|
|
server.requestTimeout = 30 * 60 * 1000;
|
2023-03-02 21:47:08 -05:00
|
|
|
|
2023-10-24 17:05:42 +02:00
|
|
|
logger.log(`Immich Server is listening on ${await app.getUrl()} [v${serverVersion}] [${envName}] `);
|
2022-02-03 10:06:44 -06:00
|
|
|
}
|