diff --git a/server/app.js b/server/app.js index dae24b13a..9729f07ba 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, getUsersBrewThemes } = require('./homebrew.api.js'); +const { homebrewApi, getBrew, getUsersBrewThemes, getCSS } = require('./homebrew.api.js'); const GoogleActions = require('./googleActions.js'); const serveCompressedStaticAssets = require('./static-assets.mv.js'); const sanitizeFilename = require('sanitize-filename'); @@ -201,20 +201,7 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ }); //Serve brew styling -app.get('/css/:id', asyncHandler(getBrew('share')), ((req, res)=>{app.getCSS(req, res);})); - -app.getCSS = (req, res)=>{ - const { brew } = req; - if(!brew) return res.status(404).send(); - splitTextStyleAndMetadata(brew); - if(!brew.style) return res.status(404).send(); - - res.set({ - 'Cache-Control' : 'no-cache', - 'Content-Type' : 'text/css' - }); - return res.status(200).send(brew.style); -}; +app.get('/css/:id', asyncHandler(getBrew('share')), (req, res)=>{getCSS(req, res);}); //User Page app.get('/user/:username', async (req, res, next)=>{ diff --git a/server/homebrew.api.js b/server/homebrew.api.js index c314454e2..52fe57360 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -148,6 +148,20 @@ const api = { next(); }; }, + + getCSS : async (req, res)=>{ + const { brew } = req; + if(!brew) return res.status(404).send(''); + splitTextStyleAndMetadata(brew); + if(!brew.style) return res.status(404).send(''); + + res.set({ + 'Cache-Control' : 'no-cache', + 'Content-Type' : 'text/css' + }); + return res.status(200).send(brew.style); + }, + mergeBrewText : (brew)=>{ let text = brew.text; if(brew.style !== undefined) {