-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS problem with http OPTIONS #1325
Comments
Having the same issue. Did you have any workaround yet ? |
i am using |
neither working to me .. T_T |
you need to allow both:
res.header('Access-Control-Allow-Origin', '*'); |
check my answer, hope that helps you as well |
check out this link: |
does it work for prod env.? |
@m00zi - is this still an issue? |
yes. I am using v10 Nodejs when developing an application in office.js |
can you print the error object in the error listener on the request? to see what we get there? also worthwhile to put a debug statement (a console log message) in the start of the request callback - just to make sure we hit the callback in the first place. |
@gireeshpunathil Thankn you for your answer! |
this part I am lacking clarity. how? Is that how node interacts with angular? I am sorry; I don't have any idea on that part. on the other hand, what if you use |
thinking further: what if you just run this client (the code in your black screen above) as a standalone node program ? and then comment out all the |
if I use console.log it doesnt print anywhere .. |
ok, let us try |
ok, somewhere in between my suggestion got lost. Let me put it again: can you please run this and share the output? const options = {
hostname: 'localhost',
port: 8888,
path: '/getLastIdOrder',
method: 'Get'
}
const req = https.request(options, (res) => {
console.log('response')
res.on('data', (d) => {
console.log(`data: ${d.toString()}`)
})
res.on('end', () => {
console.log('response ended')
})
})
req.on('error', (e) => {
console.log(`request error: ${e}`)
})
req.end() |
Hi @gireeshpunathil so the question is what should I do to make the code wait for the answer of the request and execute the rest of the function? (I already tried to use await on https.request() ,but it didnt solve the problem. At least, now we know that the https response events are fired! but practically I cant be sure to have the data returned to work on.. |
that is great! thanks for clarifying!
so the code which you are talking about here: i.e., the one that keeps running or the one that lost the context with the server response - can you please put it in the response's |
If I put the return of the sync function inside the response callback, nothing happen any more! what do you mean by : "also make sure you cache the data on the data callback, within the request callback's scope." |
on your second part, I agree: the body variable is available everywhere. I was explaining to your concern on |
no, I still ahve the same problem. |
AFAIK, the synchronization context that is used in your code is not native to node.js so I cannot say for sure what / where the problem is. If you fully remove the async-await-sync construct and resort to only callback, then placing the client code in the response' end callback is the right thing to do. |
@jolu71679 - were you able to try my suggestion? |
@hamza-khan-mhk1 |
yes |
you could use proxy to solve this issue: STEP1:
and in your angular service file you dont need to add full url in order to get or post: STEP 2:
STEP 3: edit your package.json file :
Done. |
Better solution is to add some configuration in your server
So in your header you specify the allowed referer url, for example "http://localhost:8100", which is the frontend url as well |
did you tried the steps as I explained ? #1325 (comment) |
@hari0206 , have you got this issue resolved? this issue seems to be resolved, and can be closed. |
inactive, and / or resolved, closing. pls feel free to reopen if required |
I have the following environment setup on my PC:
Node: 10.1.0
OS: darwin x64
I have problem with nodejs in https mode only, once the https mode is enabled on nodejs, I am not able to get any response from the server for POST request, but the GET requests are fine,
but once I switched back to normal http, the POST also working fine,
I have enabled cors in my nodejs in 2 method both are not working with https, I have restarted my PC and even create new nodejs app, same issue,
here is my first method to enable cors:
and here is the secod method for enabling cors, I have used 3rd party library:
The nodejs code:
this is my authService in angular:
this is my component:
this is the html:
this is the console output:
https://pasteboard.co/HoY6SfB.png
The text was updated successfully, but these errors were encountered: