A simple program that catches the response from a web site and modifies the response body according to the implemented logic.
The algorithm implemented in the program:
-
Create a server instance.
-
Create a client instance.
-
Create an app based on the server instance.
-
Define the app logic:
- Define a URI to visit for the logic to run.
- Request a URL via the client instance.
- Get the reponse and separate the reponse body.
- Modify the body: find each picture URL and add the hardcoded prefix before it.
- Send the modified response to the web browser.
-
Run the app.
- Visit https://uploadcare.com/ and create a new trial account.
- When registered, go to Dashboard and create a new project.
- Go to the project settings clicking on the newly created project.
- Click Delivery on the left navigation panel.
- Scroll down and click Connect under the Media proxy section.
- Add a domain of your choice to the list of allowed domains. By default, the program visits
yaplakal.ru
, so addwww.yapfiles.ru
ands00.yaplakal.com
if you want to test the program. - Copy your optimization URL from the Step 2 section on the page and save it somewhere on your device. The URL starts with
https://
and ends withucr.io
. For example,https://asdlkfjah43a259tlajgdad.ucr.io/
. - Click Done.
-
Install Node.js any way acceptable for you: package, apt, homebrew, yarn, etc. Use Google to find your option.
-
Install dependencies:
npm install express axios
Open a Terminal window and run:
git clone [email protected]:raproid/picture-optimizer.git && cd picture-optimizer
Open picture-optimizer.js
and replace <YOUR-UPLOADCARE-OPTIMIZER-URL>
with the URL from #7 from Prerequisites.
For example, https://asdlkfjah43a259tlajgdad.ucr.io/$1
.
Run the picture optimizer:
node picture-optimizer.js
Run the app and open the following URL in a web browser: localhost:8000/picture-optimizer
Credits to Vitaly Afonin who helped me build this program.