You are viewing our Forum Archives. To view or take place in current topics click here.
I need help with NGINX CORS
Posted:
I need help with NGINX CORSPosted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
If anyone has setup CORS on NGINX, I could use some help right now.
I'm not exactly sure what the problem is, but I think I'm having troubles sending cookies to the server.
My current setup on the server receiving the request looks like this.
I can make a post request to the server to create the cookie, but I'm having troubles sending a get request with the cookie. It is tough to debug because everything works locally.
The first request to set the cookie.
the code to request that sends the cookie needed to fetch the data.
Last edited by CriticaI ; edited 1 time in total
I'm not exactly sure what the problem is, but I think I'm having troubles sending cookies to the server.
My current setup on the server receiving the request looks like this.
location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
add_header 'Access-Control-Allow-Origin' "*" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
}
I can make a post request to the server to create the cookie, but I'm having troubles sending a get request with the cookie. It is tough to debug because everything works locally.
The first request to set the cookie.
<form action="https://api.example.com/users/login" method="POST">
<div class="field">
<input type="text" name="usernameOrEmail" placeholder="username/email" required>
<input type="password" name="password" placeholder="password" required>
</div>
<div class="field">
<button type="submit">Login</button>
</div>
</form>
the code to request that sends the cookie needed to fetch the data.
async asyncData ({app, store}) {
const auth = await axios.get('/users/auth', {withCredentials: true})
store.commit('set', auth)
}
Last edited by CriticaI ; edited 1 time in total
#2. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Post the code you're using to make both requests.
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
speed wrote Post the code you're using to make both requests.
I updated it.
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
what lang ur api running? u gotta set proper headers in the lang includin them in proxy_pass isn't gonna work
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,749
Reputation Power: 452
lamronsavage wrote what lang ur api running? u gotta set proper headers in the lang includin them in proxy_pass isn't gonna work
Node with Express and MongoDB
And I'm pretty sure I set the headers properly because the app works locally but not in production.
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
CriticaI wrotelamronsavage wrote what lang ur api running? u gotta set proper headers in the lang includin them in proxy_pass isn't gonna work
Node with Express and MongoDB
And I'm pretty sure I set the headers properly because the app works locally but not in production.
are u behind cf?
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.