From 4d2ae6231cfaee08ed528ff9d67993217dc573ab Mon Sep 17 00:00:00 2001 From: Daniel Sandoval Date: Fri, 4 Jan 2019 09:18:03 -0500 Subject: [PATCH] handle subdomain redirects on my own --- server.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 308993f..1672dbb 100644 --- a/server.js +++ b/server.js @@ -49,9 +49,14 @@ const redirects = [ { from: '/design-web', to: '/portfolio' }, { from: '/art-music', to: '/portfolio' }, { from: '/calendar', to: 'https://calendly.com/d3sandoval/30min' }, - ]; +const domainRedirects = { + www: 'https://desandoval.net', + music: 'https://open.spotify.com/artist/47mXmNmm2ekoxyCwowItaX', + alert: 'http://des-alertsystem.appspot.com/', +}; + // start express app.prepare() .then(() => { @@ -70,6 +75,22 @@ app.prepare() }); }); + // handle subdomain redirects + server.get('/', (req, res, next) => { + let redirect = false; + const subdomain = req.headers.host.split('.')[0]; + if (subdomain !== 'desandoval.net') { + if (subdomain in domainRedirects) { + redirect = true; + res.redirect(301, domainRedirects[subdomain]); + } + } + + if (!redirect) { + next(); + } + }); + server.get('/portfolio/list', (req, res) => { res.setHeader('Content-Type', 'application/json'); helper.getPortfolioList(req.query.limit, req.query.featured, (err, entries) => {