Let’s say you have the following set up:
- You have a client
- You need to access an API from the client
- But the API rejects CORS access
In this case, you can use your server as a proxy.
This means:
- You send a request from your client to your server.
- Then your server sends a request to the API server.
- When your server receives a response from the API, it sends that response back to your client.
This is a normal setup for many projects.
Here’s an example of how it would work:
// Client JSzlFetch('https://localhost:3000/link-to-resource') .then(response => { /* Do something */ })// Server JSapp.get('/link-to-resource', async (req, res) => { const response = await zlFetch('http://api.somewhere.com/link-to-resource') return res.json(response.body)})That’s all you need to know to set up a basic proxy route.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson