mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
perf: precompress and cache assets (#7757)
* perf: precompress and cache assets * fix cache header * use startswith --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com>
This commit is contained in:
parent
4fdb0835c9
commit
ba55e867e0
4 changed files with 77 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ import { NestFactory } from '@nestjs/core';
|
|||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { json } from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import sirv from 'sirv';
|
||||
import { AppModule } from './app.module';
|
||||
import { AppService } from './app.service';
|
||||
import { useSwagger } from './app.utils';
|
||||
|
|
@ -28,7 +29,20 @@ export async function bootstrap() {
|
|||
|
||||
const excludePaths = ['/.well-known/immich', '/custom.css'];
|
||||
app.setGlobalPrefix('api', { exclude: excludePaths });
|
||||
app.useStaticAssets('www');
|
||||
// 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('www', {
|
||||
etag: true,
|
||||
gzip: true,
|
||||
brotli: true,
|
||||
setHeaders: (res, pathname) => {
|
||||
if (pathname.startsWith(`/_app/immutable`) && res.statusCode === 200) {
|
||||
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
||||
}
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.use(app.get(AppService).ssr(excludePaths));
|
||||
|
||||
const server = await app.listen(port);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue