banner
LAPLACE

王友元's blog

停下来前一定要想好下次开始时需要做的事情
telegram
x
email

Use Cloudflare to reverse proxy Spotify and display embedded tracks on domestic websites.

soptify itself is not blocked, but open.spotify.com cannot be accessed due to the Great Firewall. This prevents the embedded code with open.spotify.com from loading and displaying. To enable online streaming, a simple reverse proxy for open.spotify.com can be implemented.

Here is an example:

Go to Workers and Pages.
Create a worker with the following code:

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
url.hostname = 'open.spotify.com';
const headers = new Headers(request.headers);
const response = await fetch(url.toString(), {
  method: request.method,
  headers: headers,
  body: request.body,
});
const responseHeaders = new Headers(response.headers);
return new Response(response.body, {
  status: response.status,
  statusText: response.statusText,
  headers: responseHeaders,
});
}

Bind the worker to your own domain in Settings - Triggers - Custom Domain
(The default worker domain generated by Cloudflare is blocked and cannot be used)
image

That's it. It's a standard CF worker reverse proxy process. Just change the domain of the embedded Spotify link to the one we just bound.

_L4F2_IO(2I$I(NPLKOLE

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.