projects/proxy-scalar-com/README.md
When making requests from a web browser to different domains, browsers enforce the Same-Origin Policy by default. These cross-origin requests are blocked unless the target server implements proper CORS (Cross-Origin Resource Sharing) headers.
The Scalar Proxy Server acts as an intermediary, forwarding requests to external servers while automatically adding the necessary CORS headers to the responses. This enables seamless cross-origin requests when using the Scalar API Client in browser environments.
/pingPORT)Origin header)X-Scalar-Cookie as Cookie header to circumvent the browser's cookie policyYou can start the proxy server in two ways. The default port is 1337:
go run main.go
2024/05/08 10:49:59 🥤 Proxy Server listening on http://localhost:1337
But you can customize it using the PORT environment variable:
PORT=8080 go run main.go
curl --request GET \
--url 'localhost:1337?scalar_url=https%3A%2F%2Fgalaxy.scalar.com%2Fplanets'
{
"data": [
{
"id": 1,
"name": "Mars",
"description": "The red planet",
"image": "https://cdn.scalar.com/photos/mars.jpg",
"creator": {
"id": 1,
"name": "Marc",
"email": "[email protected]"
}
}
],
"meta": {
"limit": 10,
"offset": 0,
"total": 100,
"next": "/planets?limit=10&offset=10"
}
}
We are API nerds. You too? Let's chat on Discord: https://discord.gg/scalar
The source code in this repository is licensed under MIT.