Skip to content

Commit

Permalink
🔄 feat: Add Configurable Cache Headers for Index.html (danny-avila#4565)
Browse files Browse the repository at this point in the history
* refactor: move o1 model check, after vision request check

* feat(server): add configurable cache headers for index.html

• Add environment variables to control index.html cache headers
• Default to no-cache configuration for consistent app updates
• Document cache control options in .env.example
  • Loading branch information
danny-avila authored Oct 28, 2024
1 parent a1647d7 commit b939e24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,19 @@ HELP_AND_FAQ_URL=https://librechat.ai

# E2E_USER_EMAIL=
# E2E_USER_PASSWORD=

#=====================================================#
# Cache Headers #
#=====================================================#
# Headers that control caching of the index.html #
# Default configuration prevents caching to ensure #
# users always get the latest version. Customize #
# only if you understand caching implications. #

# INDEX_HTML_CACHE_CONTROL=no-cache, no-store, must-revalidate
# INDEX_HTML_PRAGMA=no-cache
# INDEX_HTML_EXPIRES=0

# no-cache: Forces validation with server before using cached version
# no-store: Prevents storing the response entirely
# must-revalidate: Prevents using stale content when offline
4 changes: 2 additions & 2 deletions api/app/clients/OpenAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ class OpenAIClient extends BaseClient {
this.options.modelOptions,
);

this.isO1Model = /\bo1\b/i.test(this.modelOptions.model);

this.defaultVisionModel = this.options.visionModel ?? 'gpt-4-vision-preview';
if (typeof this.options.attachments?.then === 'function') {
this.options.attachments.then((attachments) => this.checkVisionRequest(attachments));
} else {
this.checkVisionRequest(this.options.attachments);
}

this.isO1Model = /\bo1\b/i.test(this.modelOptions.model);

const { OPENROUTER_API_KEY, OPENAI_FORCE_PROMPT } = process.env ?? {};
if (OPENROUTER_API_KEY && !this.azure) {
this.apiKey = OPENROUTER_API_KEY;
Expand Down
10 changes: 8 additions & 2 deletions api/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ const startServer = async () => {
app.use('/api/tags', routes.tags);

app.use((req, res) => {
// Replace lang attribute in index.html with lang from cookies or accept-language header
res.set({
'Cache-Control': process.env.INDEX_CACHE_CONTROL || 'no-cache, no-store, must-revalidate',
Pragma: process.env.INDEX_PRAGMA || 'no-cache',
Expires: process.env.INDEX_EXPIRES || '0',
});

const lang = req.cookies.lang || req.headers['accept-language']?.split(',')[0] || 'en-US';
const saneLang = lang.replace(/"/g, '"'); // sanitize untrusted user input
const saneLang = lang.replace(/"/g, '"');
const updatedIndexHtml = indexHTML.replace(/lang="en-US"/g, `lang="${saneLang}"`);
res.type('html');
res.send(updatedIndexHtml);
});

Expand Down
4 changes: 0 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Cache Busting -->
<meta http-equiv='cache-control' content="no-cache, no-store, must-revalidate">
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
<title>LibreChat</title>
<link
rel="shortcut icon"
Expand Down

0 comments on commit b939e24

Please sign in to comment.