1.1.11 • Published 8 years ago
subscription-redirects v1.1.11
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 redirectIdfrom the request route, e.g. it readsnym-home-01from/maglinks/nym-home-01.
- Fetches the published CSV of this Google Spreadsheet.
- Converts the spreadsheet data to a redirectMapthat 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 theredirectMapfor 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 requestedredirectIdand 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 redirectMapgeneration.
- The last successful redirectMapJSON.
 
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