Skip to main content
100%

Gist ca8ce8dbd8dbba7b501860f3d569f019

✓ Published0🌍 Public
115Dkatz
Last edited Jan 29, 2019
Created on Jan 29, 2019

This example demonstrates a lightweight Express server that acts as a CORS proxy for a joke API, enabling browser-based requests to bypass cross-origin restrictions. The code uses the `express` and `request` libraries to define a route, `/jokes/random`, which forwards requests to `https://joke-api-strict-cors.appspot.com/jokes/random` and relays the JSON response back to the client. A middleware sets the `Access-Control-Allow-Origin` header to `*`, allowing any frontend to access the proxied data. The server listens on a configurable port, defaulting to 3000, and handles errors by returning a JSON error object. This setup illustrates a simple server-side solution for enabling client-side data fetching from a restricted external source.

AI-generated description

Similar vizzes