Skip to content

Commit

Permalink
handle subdomain redirects on my own
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Sandoval committed Jan 4, 2019
1 parent 8b70380 commit 4d2ae62
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion server.js
Expand Up @@ -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(() => {
Expand All @@ -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) => {
Expand Down

0 comments on commit 4d2ae62

Please sign in to comment.