Skip to content

Commit 6b8b45c

Browse files
committed
fix(apps): correct error where multiple repsonses are attempted to be sent on dns redirect (#2756)
Previously the response redirect would complete the http response, but then we would attempt to still provide a status response and message, which caused errors throughout our logging. The correct action is to no longer perform response actions after a redirect. PR Close #2756
1 parent 14c3d6b commit 6b8b45c

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

apps/functions/dns-redirecting/index.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,29 @@ export const dnsRedirecting = functions.https.onRequest(
3030

3131
if (hostname === 'code-of-conduct.angular.io') {
3232
response.redirect(redirectType, 'https://code-of-conduct.angular.dev');
33-
}
34-
if (hostname === 'update.angular.dev') {
33+
} else if (hostname === 'update.angular.dev') {
3534
response.redirect(redirectType, 'https://angular.dev/update-guide');
36-
}
37-
if (hostname === 'update.angular.io') {
35+
} else if (hostname === 'update.angular.io') {
3836
response.redirect(redirectType, 'https://angular.dev/update-guide');
39-
}
40-
if (hostname === 'cli.angular.io') {
37+
} else if (hostname === 'cli.angular.io') {
4138
response.redirect(redirectType, 'https://angular.dev/tools/cli');
42-
}
43-
if (hostname === 'cli.angular.dev') {
39+
} else if (hostname === 'cli.angular.dev') {
4440
response.redirect(redirectType, 'https://angular.dev/tools/cli');
45-
}
46-
if (hostname === 'blog.angular.io') {
41+
} else if (hostname === 'blog.angular.io') {
4742
response.redirect(redirectType, `https://blog.angular.dev${request.originalUrl}`);
48-
}
49-
if (hostname === 'material.angular.io') {
43+
} else if (hostname === 'material.angular.io') {
5044
response.redirect(redirectType, `https://material.angular.dev${request.originalUrl}`);
51-
}
52-
if (hostname.endsWith('.material.angular.io')) {
45+
} else if (hostname.endsWith('.material.angular.io')) {
5346
response.redirect(
5447
redirectType,
5548
`https://${request.subdomains[0]}.material.angular.dev${request.originalUrl}`,
5649
);
50+
} else {
51+
// If no redirect is matched, we return a failure message
52+
response.status(404);
53+
response.send(
54+
`No redirect defined for ${request.protocol}://${request.hostname}${request.originalUrl}`,
55+
);
5756
}
58-
59-
// If no redirect is matched, we return a failure message
60-
response.status(404);
61-
response.send(
62-
`No redirect defined for ${request.protocol}://${request.hostname}${request.originalUrl}`,
63-
);
6457
},
6558
);

0 commit comments

Comments
 (0)