This express app acts as a small simple api-proxy server.
There are several different use-cases for this:
- The actual API you want to use does not send the cors headers you need
- You want to adjust the data in a backend before sending it to your frontend
- You are not allowed to set specific cookies directly from within the frontend
- Your own specific reason here ...
docker-compose up -d --build
yarn build
yarn start
yarn dev
Send requests to the proxy endpoint like this:
Sample url:
https://<your-endpoint-url>/proxy/<your-api-url-encoded>
https://api.publicapis.org/entries => urlencode => https%3A%2F%2Fapi.publicapis.org%2Fentries
https://my-endpoint-url.com/proxy/https%3A%2F%2Fapi.publicapis.org%2Fentries
const proxyUrl = 'https://my-endpoint-url.com';
const url = encodeURIComponent('https://api.publicapis.org/entries');
const res = await axios.get(proxyUrl + url, {
// Query params
params: {
title: 'og',
cors: 'no',
// When not using proxy, move this outside of params
headers: {
Cookie: 'key="value"',
},
},
});
return res.data;
As in the example above, cookies can be send as a query param, within the headers object.
The headers can also be send stringified with headers: JSON.stringify({Cookie: 'key="value"'}),
.