It's recommended to use this with CloudFlare caching because airtable has a limit of 5 requests per second. Also, CloudFlare can give you nice analytics for free.
First, setup an airtable account with a base and table. The table should have a column for the short code and one for the long link.
Next deploy this github repo to netlify:
Then set the following environment variables in netlify:
DEFAULT_REDIRECT_URL -> https://example.com AIRTABLE_KEY -> ***************** AIRTABLE_BASE -> ***************** AIRTABLE_TABLE -> URLs AIRTABLE_SHORT_CODE_FIELD -> Short Code AIRTABLE_LONG_LINK_FIELD -> Long Link ENABLE_CACHE -> false
ENABLE_CACHEare showing the default values above. If that's what you call your table and fields then you don't need to set those variables.
Note also that you can use a
.envfile instead, just don't commit this to source control :) (this is useful for local development as
.envis in the
Redirects should be setup automatically for you in the
netlify.toml, so you
shouldn't have to do anything there.
If that works you're on the right track!
Next, set up Netlify with a custom domain then verify that the redirect works with the custom domain.
Now, go get CloudFlare setup with your custom domain to prevent your function from being called more than airtable's rate limiting can handle.
If you're not using CloudFlare, then set
true so you can get
some caching from Netlify. That always seemed to not work very well for me
though (which is one reason I use CloudFlare instead) so good luck.