perf: omit search for immutable static requests
This commit is contained in:
parent
b95e25004f
commit
fc56a56efc
|
@ -41,7 +41,7 @@ import { ReversiGameEntityService } from '@/core/entities/ReversiGameEntityServi
|
||||||
import { FeedService } from './FeedService.js';
|
import { FeedService } from './FeedService.js';
|
||||||
import { UrlPreviewService } from './UrlPreviewService.js';
|
import { UrlPreviewService } from './UrlPreviewService.js';
|
||||||
import { ClientLoggerService } from './ClientLoggerService.js';
|
import { ClientLoggerService } from './ClientLoggerService.js';
|
||||||
import type { FastifyInstance, FastifyPluginOptions, FastifyReply } from 'fastify';
|
import type { FastifyInstance, FastifyPluginOptions, FastifyReply, onRequestHookHandler } from 'fastify';
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
const _dirname = dirname(_filename);
|
const _dirname = dirname(_filename);
|
||||||
|
@ -53,6 +53,14 @@ const swAssets = `${_dirname}/../../../../../built/_sw_dist_/`;
|
||||||
const viteOut = `${_dirname}/../../../../../built/_vite_/`;
|
const viteOut = `${_dirname}/../../../../../built/_vite_/`;
|
||||||
const tarball = `${_dirname}/../../../../../built/tarball/`;
|
const tarball = `${_dirname}/../../../../../built/tarball/`;
|
||||||
|
|
||||||
|
const handleRedirectToOmitSearch: onRequestHookHandler = (request, reply, done) => {
|
||||||
|
const index = request.url.indexOf('?');
|
||||||
|
if (~index) {
|
||||||
|
reply.redirect(301, request.url.slice(0, index));
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ClientServerService {
|
export class ClientServerService {
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
@ -253,11 +261,16 @@ export class ClientServerService {
|
||||||
|
|
||||||
//#region vite assets
|
//#region vite assets
|
||||||
if (this.config.clientManifestExists) {
|
if (this.config.clientManifestExists) {
|
||||||
fastify.register(fastifyStatic, {
|
fastify.register((fastify, options, done) => {
|
||||||
root: viteOut,
|
fastify.register(fastifyStatic, {
|
||||||
prefix: '/vite/',
|
root: viteOut,
|
||||||
maxAge: ms('30 days'),
|
prefix: '/vite/',
|
||||||
decorateReply: false,
|
maxAge: ms('30 days'),
|
||||||
|
immutable: true,
|
||||||
|
decorateReply: false,
|
||||||
|
});
|
||||||
|
fastify.addHook('onRequest', handleRedirectToOmitSearch);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const port = (process.env.VITE_PORT ?? '5173');
|
const port = (process.env.VITE_PORT ?? '5173');
|
||||||
|
@ -292,11 +305,16 @@ export class ClientServerService {
|
||||||
decorateReply: false,
|
decorateReply: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.register(fastifyStatic, {
|
fastify.register((fastify, options, done) => {
|
||||||
root: tarball,
|
fastify.register(fastifyStatic, {
|
||||||
prefix: '/tarball/',
|
root: tarball,
|
||||||
immutable: true,
|
prefix: '/tarball/',
|
||||||
decorateReply: false,
|
maxAge: ms('30 days'),
|
||||||
|
immutable: true,
|
||||||
|
decorateReply: false,
|
||||||
|
});
|
||||||
|
fastify.addHook('onRequest', handleRedirectToOmitSearch);
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get('/favicon.ico', async (request, reply) => {
|
fastify.get('/favicon.ico', async (request, reply) => {
|
||||||
|
|
Loading…
Reference in New Issue