Git Product home page Git Product logo

gcf-cors-anywhere's Introduction

gcf-cors-anywhere

An alternative to Rob--W/cors-anywhere.

gcf-cors-anywhere is a Node.js proxy which adds CORS headers to the proxied request running on Google Cloud Functions.

The url to proxy is taken from the search params ?u=, validated and proxied.

Deploy to your GCP project

Tutorial

  1. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
  2. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
  3. Enable the Cloud Functions and Cloud Build APIs.
  4. Install and initialize the Cloud SDK.
  5. Update gcloud components:
    gcloud components update
    gcloud init
  6. Deploy this function. YOU NEED TO CHANGE PROJECT_ID AND GCP_REGION.
    wget https://github.com/taichunmin/gcf-cors-anywhere/archive/master.zip -O gcf-cors-anywhere.zip
    unzip gcf-cors-anywhere.zip
    # YOU NEED TO CHANGE `PROJECT_ID` AND `GCP_REGION`.
    gcloud functions deploy cors-anywhere --allow-unauthenticated --entry-point=main --gen2 --max-instances=1 --memory=128Mi --no-user-output-enabled --project=PROJECT_ID --region=GCP_REGION --runtime=nodejs18 --timeout=60s --trigger-http --source ./gcf-cors-anywhere-master
    # clean up
    # rm -rf ./gcf-cors-anywhere.zip ./gcf-cors-anywhere-master

Usage

Use Axios and LINE Login API as example:

GET

// YOU NEED TO CHANGE `PROJECT_ID` AND `GCP_REGION`.
const result = await axios.get('https://GCP_REGION-PROJECT_ID.cloudfunctions.net/cors-anywhere', {
  params: {
    u: 'https://api.line.me/v2/profile', // your real url
    // you can add additional params here
  },
  headers: { Authorization: 'Bearer ACCESS_TOKEN' },
})
console.log(result.data)

POST

// YOU NEED TO CHANGE `PROJECT_ID` AND `GCP_REGION`.
const result = await axios.post('https://GCP_REGION-PROJECT_ID.cloudfunctions.net/cors-anywhere', Qs.stringify({
  client_id: 'CLIENT_ID',
  id_token: 'ID_TOKEN',
  nonce: 'NONCE',
  user_id: 'USER_ID',
}), {
  params: { u: 'https://api.line.me/oauth2/v2.1/verify' }, // your real url
})
console.log(result.data)

gcf-cors-anywhere's People

Contributors

taichunmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.