mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 01:11:36 +03:00
* feat(web): lighter timeline buckets * GalleryViewer * weird ssr * Remove generics from AssetInteraction * ensure keys on getAssetInfo, alt-text * empty - trigger ci * re-add alt-text * test fix * update tests * tests * missing import * feat(server): lighter buckets * fix: flappy e2e test * lint * revert settings * unneeded cast * fix after merge * Adapt web client to consume new server response format * test * missing import * lint * Use nulls, make-sql * openapi battle * date->string * tests * tests * lint/tests * lint * test * push aggregation to query * openapi * stack as tuple * openapi * update references to description * update alt text tests * update sql * update sql * update timeline tests * linting, fix expected response * string tuple * fix spec * fix * silly generator * rename patch * minimize sorting * review * lint * lint * sql * test * avoid abbreviations * review comment - type safety in test * merge conflicts * lint * lint/abbreviations * remove unncessary code * review comments * sql * re-add package-lock * use booleans, fix visibility in openapi spec, less cursed controller * update sql * no need to use sql template * array access actually doesn't seem to matter * remove redundant code * re-add sql decorator * unused type * remove null assertions * bad merge * Fix test * shave * extra clean shave * use decorator for content type * redundant types * redundant comment * update comment * unnecessary res --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { json } from 'body-parser';
|
|
import compression from 'compression';
|
|
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 { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
|
import { bootstrapTelemetry } from 'src/repositories/telemetry.repository';
|
|
import { ApiService } from 'src/services/api.service';
|
|
import { isStartUpError, useSwagger } from 'src/utils/misc';
|
|
async function bootstrap() {
|
|
process.title = 'immich-api';
|
|
|
|
const { telemetry, network } = new ConfigRepository().getEnv();
|
|
if (telemetry.metrics.size > 0) {
|
|
bootstrapTelemetry(telemetry.apiPort);
|
|
}
|
|
|
|
const app = await NestFactory.create<NestExpressApplication>(ApiModule, { bufferLogs: true });
|
|
const logger = await app.resolve(LoggingRepository);
|
|
const configRepository = app.get(ConfigRepository);
|
|
|
|
const { environment, host, port, resourcePaths } = configRepository.getEnv();
|
|
const isDev = environment === ImmichEnvironment.DEVELOPMENT;
|
|
|
|
logger.setContext('Bootstrap');
|
|
app.useLogger(logger);
|
|
app.set('trust proxy', ['loopback', ...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));
|
|
app.use(compression());
|
|
|
|
const server = await (host ? app.listen(port, host) : app.listen(port));
|
|
server.requestTimeout = 24 * 60 * 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);
|
|
});
|