adhocteam / nytimes-library

A collaborative documentation site, powered by Google Docs.
https://nyt-library-demo.herokuapp.com/
Apache License 2.0
1 stars 1 forks source link

Added route hooks #25

Closed zenkimoto closed 2 years ago

zenkimoto commented 2 years ago

Part of #24

Description of Change

Related Issue

Motivation and Context

When trying to add a single property fileType, I tried multiple ways of customizing the route handlers without modifying the base code. The default approach was to create middleware. However, this proved to be problematic. The way to customize a response is to:

  1. Create preloader middleware
  2. Override response.send()
  3. Read the payload and modify payload as needed. <- I was at this step...

Seems a bit complicated if I just wanted to add a filetype property. Luckily, I found that this can be easily done on the frontend and chose to do it that way. However, I can see this could be problematic in the future depending on what type of customizations that we want to do.

This change allows you to create a custom route handler by just simply copying the files in /server/routes and put them in /custom/routes and modifying it as needed. However, one caveat is the require() calls will need to be remapped to the /server versions.

Checklist