From 7414f22bdef137396021ef4b5db7524eb9237b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kol=C3=A1rik?= Date: Fri, 22 Nov 2024 16:27:13 +0100 Subject: [PATCH] Remove /blog from GP --- src/index.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/index.js b/src/index.js index f41debc85..a15aa74a6 100644 --- a/src/index.js +++ b/src/index.js @@ -328,33 +328,35 @@ server.use((req, res, next) => { next(); }); -server.use('/blog/robots.txt', (req, res) => { - res.set('Content-Type', 'text/plain'); - return res.send(`User-agent: * +if (site === 'jsdelivr') { + server.use('/blog/robots.txt', (req, res) => { + res.set('Content-Type', 'text/plain'); + return res.send(`User-agent: * Sitemap: ${serverConfig.host}/blog/sitemap.xml Disallow: /ghost/ Disallow: /p/ Disallow: /email/ Disallow: /r/`); -}); + }); -/** - * Redirect old blog posts. - */ -server.use('/blog', (req, res, next) => { - if (Object.hasOwn(serverConfig.blogRewrite, req.path)) { - return res.redirect(301, `${serverConfig.host}${serverConfig.blogRewrite[req.path]}`); - } else if (req.hostname === 'blog.jsdelivr.com') { - return res.redirect(301, `${serverConfig.host}/blog${req.path}`); - } + /** + * Redirect old blog posts. + */ + server.use('/blog', (req, res, next) => { + if (Object.hasOwn(serverConfig.blogRewrite, req.path)) { + return res.redirect(301, `${serverConfig.host}${serverConfig.blogRewrite[req.path]}`); + } else if (req.hostname === 'blog.jsdelivr.com') { + return res.redirect(301, `${serverConfig.host}/blog${req.path}`); + } - next(); -}); + next(); + }); -/** - * Proxy blog requests to ghost. - */ -server.use('/blog', proxy(serverConfig.blogHost, app.env === 'development' ? `http://localhost:${serverConfig.port}` : serverConfig.host)); + /** + * Proxy blog requests to ghost. + */ + server.use('/blog', proxy(serverConfig.blogHost, app.env === 'development' ? `http://localhost:${serverConfig.port}` : serverConfig.host)); +} /** * Forward everything else to Koa (main website).