Skip to content

shaklain125/netlify_cors_http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

netlify_cors_http

A serverless CORS proxy to make cross-origin requests anywhere

https://cors-http.netlify.app/.netlify/functions/api

Try it out in the browser's devtools console

Note: Cross-origin requests may still be blocked when using the devtools on some sites. You may encounter a Content Security Policy error or similar.

const cors_req_url = ({ url, method, data, headers }) =>
  `${`https://cors-http.netlify.app/.netlify/functions/api`}${((o) => {
    const p = Object.entries(o)
      .filter(([_, v]) => Boolean(v))
      .map((kv) => kv.map((v) => encodeURIComponent(v.toString())))
      .map((kv) => kv.join('='))
      .join('&');
    return Boolean(p) ? `?${p}` : '';
  })({
    method,
    data,
    headers: headers ? JSON.stringify(headers) : undefined,
    url,
  })}`;

fetch(cors_req_url({ url: 'https://example.com/' }))
  .then((response) => response.text())
  .then(console.log);

Api usage

[GET] https://cors-http.netlify.app/.netlify/functions/api?{param}={value}

Param Value Description
url string The target request url
method e.g. GET POST HEAD A HTTP method type. The default method type is GET
data string, json stringified The HTTP Post body
headers json stringified The headers to send to the target url

Libraries

  • Express
  • Serverless-http
  • Axios