Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions apps/functions/dns-redirecting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const dnsRedirecting = functions.https.onRequest(
maxInstances: 2,
},
async (request, response) => {
console.log(`Request made at: ${request.protocol}://${request.hostname}${request.originalUrl}`);
/** The type of redirect to use, defaulting to a 301 permanent redirect. */
let redirectType = 301;
/** The hostname that was used for the request. */
Expand All @@ -30,36 +31,29 @@ export const dnsRedirecting = functions.https.onRequest(

if (hostname === 'code-of-conduct.angular.io') {
response.redirect(redirectType, 'https://code-of-conduct.angular.dev');
}
if (hostname === 'update.angular.dev') {
} else if (hostname === 'update.angular.dev') {
response.redirect(redirectType, 'https://angular.dev/update-guide');
}
if (hostname === 'update.angular.io') {
} else if (hostname === 'update.angular.io') {
response.redirect(redirectType, 'https://angular.dev/update-guide');
}
if (hostname === 'cli.angular.io') {
} else if (hostname === 'cli.angular.io') {
response.redirect(redirectType, 'https://angular.dev/tools/cli');
}
if (hostname === 'cli.angular.dev') {
} else if (hostname === 'cli.angular.dev') {
response.redirect(redirectType, 'https://angular.dev/tools/cli');
}
if (hostname === 'blog.angular.io') {
} else if (hostname === 'blog.angular.io') {
response.redirect(redirectType, `https://blog.angular.dev${request.originalUrl}`);
}
if (hostname === 'material.angular.io') {
} else if (hostname === 'material.angular.io') {
response.redirect(redirectType, `https://material.angular.dev${request.originalUrl}`);
}
if (hostname.endsWith('.material.angular.io')) {
} else if (hostname.endsWith('.material.angular.io')) {
response.redirect(
redirectType,
`https://${request.subdomains[0]}.material.angular.dev${request.originalUrl}`,
`https://${request.subdomains.reverse().join('.')}.angular.dev${request.originalUrl}`,
);
} else {
// If no redirect is matched, we return a failure message
response.status(404);
response.send(
`No redirect defined for ${request.protocol}://${request.hostname}${request.originalUrl}`,
);
}

// If no redirect is matched, we return a failure message
response.status(404);
response.send(
`No redirect defined for ${request.protocol}://${request.hostname}${request.originalUrl}`,
);
},
);