From 3e66647f9ff2318575c4f1923da7984ef8214c32 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Fri, 23 Feb 2024 14:43:29 -0600 Subject: [PATCH] Fix @import loading on Chrome. --- server/app.js | 2 +- server/homebrew.api.js | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/server/app.js b/server/app.js index 7d1eaf577..38e4f2112 100644 --- a/server/app.js +++ b/server/app.js @@ -9,7 +9,7 @@ const yaml = require('js-yaml'); const app = express(); const config = require('./config.js'); -const { homebrewApi, getBrew, getBrewThemeWithCSS, getStaticTheme} = require('./homebrew.api.js'); +const { homebrewApi, getBrew, getBrewThemeWithCSS, getStaticTheme } = require('./homebrew.api.js'); const GoogleActions = require('./googleActions.js'); const serveCompressedStaticAssets = require('./static-assets.mv.js'); const sanitizeFilename = require('sanitize-filename'); diff --git a/server/homebrew.api.js b/server/homebrew.api.js index f01c7320c..feeecfbbc 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -238,12 +238,10 @@ const api = { getBrewThemeWithCSS : async (req, res)=>{ const brew = req.brew; splitTextStyleAndMetadata(brew); - // if(res.hasOwnProperty('set')) { - // res.set('Content-Type', 'text/css'); - // } + res.set('Content-Type', 'text/css'); const staticTheme = `/api/css/${req.brew.renderer}/${req.brew.theme}/styles.css`; const userTheme = `/api/css/${req.brew.theme.slice(1)}`; - const parentThemeImport = `@import url(\"${req.brew.theme[0] != '#' ? staticTheme : userTheme}\");\n\n// From Theme: ${req.brew.title}\n\n`; + const parentThemeImport = `@import url(\"${req.brew.theme[0] != '#' ? staticTheme : userTheme}\");\n\n/* From Brew: ${req.brew.title}*/\n\n`; return res.status(200).send(`${req.brew.renderer == 'legacy' ? '' : parentThemeImport}${req.brew.style}`); }, getStaticTheme : async(req, res)=>{ @@ -251,11 +249,10 @@ const api = { if(themeParent === undefined){ res.status(404).send(`Invalid Theme - Engine: ${req.params.engine}, Name: ${req.params.id}`); } else { - // if(res.hasOwnProperty('set')) { - // res.set('Content-Type', 'text/css'); - // } - const parentTheme = themeParent ? `@import url(\"/css/${req.params.engine}/${themeParent}\");\n` : ''; - return res.status(200).send(`${parentTheme}@import url(\"/themes/${req.params.engine}/${req.params.id}/style.css\");\n`); + res.setHeader('Content-Type', 'text/css'); + res.setHeader('Cache-Control', 'public, max-age: 43200, must-revalidate'); + const parentTheme = themeParent ? `@import url(\"/css/${req.params.engine}/${themeParent}\");\n/* Static Theme ${themes[req.params.engine][themeParent].name} */\n` : ''; + return res.status(200).send(`${parentTheme}@import url(\"/themes/${req.params.engine}/${req.params.id}/style.css\");\n/* Static Theme ${themes[req.params.engine][req.params.id].name} */\n`); } }, updateBrew : async (req, res)=>{