Redirects - Evaluate at what infrastructure level these will happen
Overview
Assessing the most suitable platform to host our redirects. The current options we are exploring are Cloudflare Workers, Cloudflare Bulk Redirects or Vercel.
Cloudflare Workers
Price
Cloudflare Workers have the clearest payment structure for hosting CF Workers. If we take an average of 1 million requests a day we would be looking at 15 dollars a month not inlucing the first 10 million we get included for our paid plan.
Technical considerations
Cloudflare Bulk Redirects
Price
This option is already covered under our current plan and should not incur any further costs.
Technical considerations
Cloudflare Bulk Redirects is still in beta although there is documentation attached bellow. We can leverage CF analytics, something that we are currently using.
Vercel
Price
What we would need to look into is the exact breakdown of cost. In addion we would need clarification on if 500,000 invocations per day was for each edge function or the total invocations across the whole account. It is most likely that would indeed be the total amount but it would be worth consulting with a success/account manager over at Vercel
Technical considerations
Currently whenever a user hits our site the request will always pass through a page rule in Cloudflare. This means if we want to host out redirects outside of Cloudflare the request (once redirected) will inevitably have to go via cloudflare again once the client has the new url. This extra step could be seen as a potential pain point in the future which may be worth looking into.
Next.js does have a redirects module we could use which inculdes the option to match a redirect when a header, cookie, or query values also match:
module.exports = {
async redirects() {
return [
// if the header `x-redirect-me` is present,
// this redirect will be applied
{
source: '/:path((?!another-page$).*)',
has: [
{
type: 'header',
key: 'x-redirect-me',
},
],
permanent: false,
destination: '/another-page',
},
// if the source, query, and cookie are matched,
// this redirect will be applied
{
source: '/specific/:path*',
has: [
{
type: 'query',
key: 'page',
// the page value will not be available in the
// destination since value is provided and doesn't
// use a named capture group e.g. (?<page>home)
value: 'home',
},
{
type: 'cookie',
key: 'authorized',
value: 'true',
},
],
permanent: false,
destination: '/another/:path*',
},
// if the header `x-authorized` is present and
// contains a matching value, this redirect will be applied
{
source: '/',
has: [
{
type: 'header',
key: 'x-authorized',
value: '(?<authorized>yes|true)',
},
],
permanent: false,
destination: '/home?authorized=:authorized',
},
// if the host is `example.com`,
// this redirect will be applied
{
source: '/:path((?!another-page$).*)',
has: [
{
type: 'host',
value: 'example.com',
},
],
permanent: false,
destination: '/another-page',
},
]
},
}
Decision
Taking into consideration our current routing using Cloudflare, we believe it would be optimal to host our redirects within Cloudflare's network. The main reason for this would be to reduce the number of hops required for a user to connect to the site. Hosting the redirects outside of Cloudflare would require the client to pass through its page rule system more than once.
Resouces
1.Bulk Redirects 2.Cloudflare Workers - Pricing 3.About Cloudflare Analytics