mirror of
https://github.com/immich-app/immich.git
synced 2025-11-13 04:02:35 +09:00
Some checks are pending
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker / pre-job (push) Waiting to run
Docker / Re-Tag ML () (push) Blocked by required conditions
Docker / Re-Tag ML (-armnn) (push) Blocked by required conditions
Docker / Re-Tag ML (-cuda) (push) Blocked by required conditions
Docker / Re-Tag ML (-openvino) (push) Blocked by required conditions
Docker / Re-Tag Server () (push) Blocked by required conditions
Docker / Build and Push ML (armnn, linux/arm64, -armnn) (push) Blocked by required conditions
Docker / Build and Push ML (cpu, linux/amd64,linux/arm64) (push) Blocked by required conditions
Docker / Build and Push ML (cuda, linux/amd64, -cuda) (push) Blocked by required conditions
Docker / Build and Push ML (openvino, linux/amd64, -openvino) (push) Blocked by required conditions
Docker / Build and Push Server (cpu, linux/amd64,linux/arm64) (push) Blocked by required conditions
Docker / Docker Build & Push Server Success (push) Blocked by required conditions
Docker / Docker Build & Push ML Success (push) Blocked by required conditions
Docs build / pre-job (push) Waiting to run
Docs build / Docs Build (push) Blocked by required conditions
Static Code Analysis / pre-job (push) Waiting to run
Static Code Analysis / Run Dart Code Analysis (push) Blocked by required conditions
Test / pre-job (push) Waiting to run
Test / Test & Lint Server (push) Blocked by required conditions
Test / Unit Test CLI (push) Blocked by required conditions
Test / Unit Test CLI (Windows) (push) Blocked by required conditions
Test / Test & Lint Web (push) Blocked by required conditions
Test / End-to-End Lint (push) Blocked by required conditions
Test / Medium Tests (Server) (push) Blocked by required conditions
Test / End-to-End Tests (Server & CLI) (push) Blocked by required conditions
Test / End-to-End Tests (Web) (push) Blocked by required conditions
Test / Unit Test Mobile (push) Blocked by required conditions
Test / Unit Test ML (push) Blocked by required conditions
Test / ShellCheck (push) Waiting to run
Test / OpenAPI Clients (push) Waiting to run
Test / TypeORM Checks (push) Waiting to run
77 lines
2.9 KiB
TypeScript
77 lines
2.9 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { json } from 'body-parser';
|
|
import cookieParser from 'cookie-parser';
|
|
import { existsSync } from 'node:fs';
|
|
import sirv from 'sirv';
|
|
import { ApiModule } from 'src/app.module';
|
|
import { excludePaths, serverVersion } from 'src/constants';
|
|
import { ImmichEnvironment } from 'src/enum';
|
|
import { IConfigRepository } from 'src/interfaces/config.interface';
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
|
import { ApiService } from 'src/services/api.service';
|
|
import { isStartUpError } from 'src/services/storage.service';
|
|
import { otelStart } from 'src/utils/instrumentation';
|
|
import { useSwagger } from 'src/utils/misc';
|
|
|
|
async function bootstrap() {
|
|
process.title = 'immich-api';
|
|
|
|
const { telemetry, network } = new ConfigRepository().getEnv();
|
|
otelStart(telemetry.apiPort);
|
|
|
|
const app = await NestFactory.create<NestExpressApplication>(ApiModule, { bufferLogs: true });
|
|
const logger = await app.resolve<ILoggerRepository>(ILoggerRepository);
|
|
const configRepository = app.get<IConfigRepository>(IConfigRepository);
|
|
|
|
const { environment, host, port, resourcePaths } = configRepository.getEnv();
|
|
const isDev = environment === ImmichEnvironment.DEVELOPMENT;
|
|
|
|
logger.setContext('Bootstrap');
|
|
app.useLogger(logger);
|
|
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal', ...network.trustedProxies]);
|
|
app.set('etag', 'strong');
|
|
app.use(cookieParser());
|
|
app.use(json({ limit: '10mb' }));
|
|
if (isDev) {
|
|
app.enableCors();
|
|
}
|
|
app.useWebSocketAdapter(new WebSocketAdapter(app));
|
|
useSwagger(app, { write: isDev });
|
|
|
|
app.setGlobalPrefix('api', { exclude: excludePaths });
|
|
if (existsSync(resourcePaths.web.root)) {
|
|
// copied from https://github.com/sveltejs/kit/blob/679b5989fe62e3964b9a73b712d7b41831aa1f07/packages/adapter-node/src/handler.js#L46
|
|
// provides serving of precompressed assets and caching of immutable assets
|
|
app.use(
|
|
sirv(resourcePaths.web.root, {
|
|
etag: true,
|
|
gzip: true,
|
|
brotli: true,
|
|
extensions: [],
|
|
setHeaders: (res, pathname) => {
|
|
if (pathname.startsWith(`/_app/immutable`) && res.statusCode === 200) {
|
|
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
}
|
|
},
|
|
}),
|
|
);
|
|
}
|
|
app.use(app.get(ApiService).ssr(excludePaths));
|
|
|
|
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}] [${environment}] `);
|
|
}
|
|
|
|
bootstrap().catch((error) => {
|
|
if (!isStartUpError(error)) {
|
|
console.error(error);
|
|
}
|
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
process.exit(1);
|
|
});
|