subscription-redirects
v1.1.11
Published
This app routes various marketing links that appear across New York Magazine systems. The redirect destinations are managed by the marketing team in a [Google Spreadsheet](https://docs.google.com/spreadsheets/d/132qVfE4fQdhHcTf0QwnJKgdT9h7d45myvxPpAwo_Un4
Downloads
6
Readme
Subscription Redirects
This app routes various marketing links that appear across New York Magazine systems. The redirect destinations are managed by the marketing team in a Google Spreadsheet.
On each request, the app:
- Reads a
redirectId
from the request route, e.g. it readsnym-home-01
from/maglinks/nym-home-01
. - Fetches the published CSV of this Google Spreadsheet.
- Converts the spreadsheet data to a
redirectMap
that maps redirect IDs to possible redirect URLs. - Validates the
redirectMap
, ensuring that all URLs are valid (e.g. URLs without protocols will not pass). If valid, caches theredirectMap
for one hour and continues with it to the next step. If invalid, continues with the last validredirectMap
. - Using the
redirectMap
, finds the possible redirect URLs for the requestedredirectId
and picks one at random. - Redirects the request to the chosen URL.
A GET request on /maglinks/recache
forces a recache attempt and outputs JSON indicating the following:
- If the recache was successful:
- A message indicating that it was successful.
- The resulting
redirectMap
.
- If the recache failed:
- A message indicating that it failed.
- Errors that arose in the fetch/validation processes.
- The datetime of the last successful
redirectMap
generation. - The last successful
redirectMap
JSON.
Note: It takes a few minutes after re-publishing a spreadsheet in Google Docs for the published CSV to show recent changes consistently.
Quickstart
npm install
npm run start
Testing
npm install --dev-only
npm run test