Comments (11)
With regards to the Missing required request header. Must specify one of: origin,x-requested-with
message when navigating to https://proxy-hwp6dcya3a-uc.a.run.app/https://exp.host/--/api/v2/push/send
from the browser - that is to be expected. It is what we specified within the requireHeader
field in index.js
. Have a look at the CORS Anywhere documentation on the subject. The requirement for these headers is to prevent users from using the proxy for normal browsing (i.e. only intended for HTTP requests). However, cURL commands don't attach those headers either.
As a demonstration, run curl -H "Content-Type: application/json" -X POST "postman-echo.com/post"
- you will get the expected response. Then try prepending with your proxy, i.e. curl -H "Content-Type: application/json" -X POST "https://proxy-hwp6dcya3a-uc.a.run.app/postman-echo.com/post"
and you will get the Missing required request header
message as with your request. Finally, add the header i.e. curl -H "origin: http://localhost:3000" -H "Content-Type: application/json" -X POST "https://proxy-hwp6dcya3a-uc.a.run.app/postman-echo.com/post"
to the proxied request and it will work.
I successfully ran the POST request without the proxy via cURL and separately using Postman, getting the following response:
{"data":{"status":"ok","id":"83d56fba-b332-419f-902c-5cb62d48feef"}}
. Using the proxy and attaching an origin
header per the demo above results in upstream connect error or disconnect/reset before headers. retried and the latest reset reason: connection termination
Hopefully the above might be of some use, though it doesn't resolve the issue. I'll have another look later when I have time.
from cors-server.
Also, have you tested with a local instance of cors-server
and locally hosting the website making the API request? If so do you experience the same issue as when hosting both remotely?
from cors-server.
I had another little look at it. So when I use your proxy server in the ravenous app (my use case), it works fine. You can fork that repo and give it a go if you like.
Also, don't worry about the 204
response - that is normal and will be present with a successful request too (i.e. you will get a 204
and a 200
when successful).
The problem likely lies with the API endpoint that you are trying to reach. The server might have a problem with the use of a proxy (hence the 503 Service Unavailable
error).
from cors-server.
In case anyone else looks at this, I recreated the errors by replacing the contents of searchYelp
with the code below:
async function searchYelp(term, location, priceString, sortBy) {
const corsProxy = "https://proxy-ibmasyzzya-uc.a.run.app/";
const restoredTemeculaApi = "https://exp.host/--/api/v2/push/send";
const data = { "to": "ExponentPushToken[dhLJeWNqW61r1ZBUkAwOtA]", "title":"hello", "body": "world" };
const fetchOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
};
const response = await fetch(corsProxy + restoredTemeculaApi, fetchOptions);
console.log(response);
return response;
}
export default searchYelp;
The BusinessList
component in App.js
also needs to be removed in order for the app to build.
Responses for 204 No Content
and 503 Service Unavailable
will be displayed in the GCF logs associated with the proxy server, accessable from the Firebase console in the browser as pointed out by @restoredtemecula. The 503
is also in the browser console after the request fails.
from cors-server.
Thanks for looking into this with me. The oddity here is that it was working totally fine in the Heroku environment. I also spent a couple minutes, as a contingency, migrating the few Heroku apps I built over to railway and cors-anywhere works fine in that environment too. The draw to firebase was that, for the same project, I use firestore and realtime db, so I thought it'd be nice to house it all in one place. It might be a bit over my head at this point to figure out how to make cors-anywhere work on firebase at this point. Not as simple a migration as I had hoped, and I am a noob.
from cors-server.
Sure, not a problem. So just to clarify, had you previously hosted your cors-server
on Heroku where it was working fine and migrating to Firebase resulted in the 503
error for some API requests passing through it? Or was it moving the apps themselves from Heroku to Firebase that caused the issue? Also, do you control the server that hosts the https://exp.host/--/api/v2/push/send
endpoint and if so how is that hosted and did it change?
I would advise opening an issue on the actual cors-anywhere
repo and try to be very specific on what arrangement worked and what didn't. The author of that repo knows much more than me about it, though he's busy so might not get time.
Failing that, I would suggest using Heroku if that worked for you before. They have revised their pricing so you can get a dyno for 1ยข per hour uptime.
from cors-server.
So to clarify, it was the former scenario you mentioned above, I had "previously hosted your cors-server on Heroku where it was working fine and migrating to Firebase resulted in the 503 error for some API requests passing through it?" And to further clarify, everything works currently without changing a single line of code (on my end) after migrating to railway, which for the scale of my usage will likely keep me in a free tier for the foreseeable future.
I changed nothing in attempting to work with firebase functions apart from what you listed in your instructions. I will still spend some time looking into it and seeing if I can get the issue with cors-server on firebase worked out, but the railway tech seems to be VERY user friendly and functional for me for the time being, so getting it up on firebase is less urgent at this point.
Thanks again for all the help and the suggestions. I think Railway is a huge win, at least for the projects that I had on Heroku. A very seamless transition, and a great looking UI.
from cors-server.
Yeah Railway have a nice platform alright. Hopefully they don't cut you off like they did with me near the end of the month.
Also if you do figure out a solution, please post it here to help others experiencing the same issue.
from cors-server.
Hi @restoredtemecula. Maybe you have seen this already, but fly.io might be your best bet if and when you run out of Railway hours.
I'll close out the issue as that should resolve your problem. The 503
was specific to Firebase and the server / API endpoint you were attempting to reach. Feel free to reopen the issue if the need arises.
from cors-server.
Possibly related: https://github.com/Rob--W/cors-anywhere/issues/445
from cors-server.
Yes that's interesting. Works when sending a POST request to Postman using either the proxy or with a data payload, but not both.
Maybe there is an issue sending data with the Firebase implementation of cors-server
. My use case only involves a GET request to the Yelp API, would be good to know if anyone has successfully sent data via a POST request using it...
from cors-server.
Related Issues (9)
- Http-Proxy HOT 33
- fastly HOT 3
- Error 504 on my request HOT 8
- Different behavior between cors-everywhere webpage and Firebase cors-server HOT 2
- GitHub Codespaces
- Getting cors error even after following all the steps you have mentioned on readme HOT 3
- When trying to deploy using Firebase Functions, I keep getting an error HOT 4
- Help for vercel deployment HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cors-server.