mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-18 13:10:40 +01:00
Add cache buster middleware to clear browser cache on server restart
This commit is contained in:
parent
96d6a6df07
commit
bae02a44ed
@ -60,6 +60,7 @@ import basicAuthMiddleware from './src/middleware/basicAuth.js';
|
||||
import whitelistMiddleware from './src/middleware/whitelist.js';
|
||||
import multerMonkeyPatch from './src/middleware/multerMonkeyPatch.js';
|
||||
import initRequestProxy from './src/request-proxy.js';
|
||||
import getCacheBusterMiddleware from './src/middleware/cacheBuster.js';
|
||||
import {
|
||||
getVersion,
|
||||
getConfigValue,
|
||||
@ -515,7 +516,7 @@ if (!disableCsrf) {
|
||||
|
||||
// Static files
|
||||
// Host index page
|
||||
app.get('/', (request, response) => {
|
||||
app.get('/', getCacheBusterMiddleware(), (request, response) => {
|
||||
if (shouldRedirectToLogin(request)) {
|
||||
const query = request.url.split('?')[1];
|
||||
const redirectUrl = query ? `/login?${query}` : '/login';
|
||||
|
22
src/middleware/cacheBuster.js
Normal file
22
src/middleware/cacheBuster.js
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Middleware to bust the browser cache for the current user.
|
||||
* @returns {import('express').RequestHandler}
|
||||
*/
|
||||
export default function getCacheBusterMiddleware() {
|
||||
/**
|
||||
* @type {Set<string>} Handles that have already been busted.
|
||||
*/
|
||||
const handles = new Set();
|
||||
|
||||
return (request, response, next) => {
|
||||
const handle = request.user?.profile?.handle;
|
||||
|
||||
if (!handle || handles.has(handle)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
handles.add(handle);
|
||||
response.setHeader('Clear-Site-Data', '"cache"');
|
||||
next();
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user