0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-09 07:12:40 +00:00

Update server.js

Initial commit of incorporating `brew.style` into /source and /download pages
This commit is contained in:
Sean Robertson
2021-06-18 11:24:20 +12:00
parent 9d80f21ae7
commit 4638c3e1d9

View File

@@ -113,7 +113,7 @@ app.get('/source/:id', asyncHandler(async (req, res)=>{
const brew = await getBrewFromId(req.params.id, 'share'); const brew = await getBrewFromId(req.params.id, 'share');
const replaceStrings = { '&': '&amp;', '<': '&lt;', '>': '&gt;' }; const replaceStrings = { '&': '&amp;', '<': '&lt;', '>': '&gt;' };
let text = brew.text; let text = `\`\`\`css\n${brew.style}\n\`\`\`\n\n${brew.text}`;
for (const replaceStr in replaceStrings) { for (const replaceStr in replaceStrings) {
text = text.replaceAll(replaceStr, replaceStrings[replaceStr]); text = text.replaceAll(replaceStr, replaceStrings[replaceStr]);
} }
@@ -132,8 +132,9 @@ app.get('/download/:id', asyncHandler(async (req, res)=>{
'Cache-Control' : 'no-cache', 'Cache-Control' : 'no-cache',
'Content-Type' : 'text/plain', 'Content-Type' : 'text/plain',
'Content-Disposition' : `attachment; filename="${fileName}.txt"` 'Content-Disposition' : `attachment; filename="${fileName}.txt"`
}); });
res.status(200).send(brew.text); let text = `\`\`\`css\n${brew.style}\n\`\`\`\n\n${brew.text}`;
res.status(200).send(text);
})); }));
//User Page //User Page