Using lambda to get around cors

github logo ・1 min read

I am building my portfolio and one of the requirements is to not get tied to a web server, in fact I am probably going to host in S3 for the time being. There is one particular API which I want to request in the browser, the GitHub API over graphql, unfortunately I get cors issues as you might expect. So my idea was to create a lambda that makes that request and returns the result. Is this a good use of a lambda? It strikes me that I am making 2 requests. Even then I am struggling to configure cors. I have to say though the serverless framework has been very helpful.

twitter logo DISCUSS (3)
markdown guide
 

On your S3 bucket you can set CORS

If the API call you are making is a public API and not with credentials then it would make sense to call this from your javascript code.

If it is credentialed information you'd want to use a Lambda which you can back by API Gateway.

 

Looks like I choose wisely, it was the latter. My personal API oauth token is now in environmental variables in both local .env file.

I wondered how much work my lambda should do alter the result in a format I need so compute would do all the work, but instead I went with returning the data as is.

Either way this is my first lambda and a great intro into serverless.

 

Update, I don't know what happened between last night and this morning but my lambda now returns data to my browser, nieeeeeece!

Classic DEV Post from May 21

How to handle outbound links in desktop PWA?

Adam Crockett profile image
I work at Dyson as a Front end focused Full stack developer, I play with all sorts really. Lately WASM is my toy of interest.

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️