subscription-redirects

1.1.11 • Public • Published

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:

  1. Reads a redirectId from the request route, e.g. it reads nym-home-01 from /maglinks/nym-home-01.
  2. Fetches the published CSV of this Google Spreadsheet.
  3. Converts the spreadsheet data to a redirectMap that maps redirect IDs to possible redirect URLs.
  4. Validates the redirectMap, ensuring that all URLs are valid (e.g. URLs without protocols will not pass). If valid, caches the redirectMap for one hour and continues with it to the next step. If invalid, continues with the last valid redirectMap.
  5. Using the redirectMap, finds the possible redirect URLs for the requested redirectId and picks one at random.
  6. 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

Readme

Keywords

none

Package Sidebar

Install

npm i subscription-redirects

Weekly Downloads

0

Version

1.1.11

License

ISC

Last publish

Collaborators

  • chrkirk