ProgrammingI need help with NGINX CORSPosted:

CriticaI
  • 2 Million
Status: Offline
Joined: Nov 05, 20134 Year Member
Posts: 2,592
Reputation Power: 146
Motto: Do What You Can't
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.
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:
speed
  • Administrator
Status: Offline
Joined: Jun 11, 20098 Year Member
Posts: 9,876
Reputation Power: 3062
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.
#3. Posted:
CriticaI
  • 1K Rainmaker
Status: Offline
Joined: Nov 05, 20134 Year Member
Posts: 2,592
Reputation Power: 146
Motto: Do What You Can't
speed wrotePost the code you're using to make both requests.

I updated it.
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS