feat: add shareable meme permalinks
This commit is contained in:
@@ -75,6 +75,21 @@ const server = http.createServer(async (req, res) => {
|
||||
}));
|
||||
}
|
||||
|
||||
const memePageMatch = url.pathname.match(/^\/meme\/([a-f0-9]{64})\/?$/);
|
||||
if (req.method === 'GET' && memePageMatch) {
|
||||
const meme = store.get(memePageMatch[1]);
|
||||
if (!meme || meme.status !== 'approved') return sendText(res, 404, 'Not found');
|
||||
const nonce = crypto.randomBytes(16).toString('base64');
|
||||
withSecurityHeaders(res, { scriptNonce: nonce });
|
||||
return sendHtml(res, 200, renderIndex({
|
||||
template: indexTemplate,
|
||||
baseUrl,
|
||||
nonce,
|
||||
approvedCount: store.count('approved'),
|
||||
meme: publicMeme(meme)
|
||||
}));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && url.pathname === '/openapi.json') {
|
||||
res.setHeader('Cache-Control', 'public, max-age=300');
|
||||
return sendJson(res, 200, openApiSpecFor(baseUrl));
|
||||
|
||||
Reference in New Issue
Block a user