Skip to content

I don’t manage to call an API from Vue.js #6281

Answered by tYYGH
tYYGH asked this question in Help/Questions
Discussion options

You must be logged in to vote

In the end, I fully handled CORS, as I did not manage to do otherwise. So:

  • All my web API endpoints now return
    • either Access-Control-Allow-Origin: * if no Origin header was received,
    • or Access-Control-Allow-Origin: _Origin_ (actual value) if an Origin was received.
  • In Nginx, I added the configuration for OPTIONS handling:
    …
    http {
        …
        map $http_origin $allow_origin {
            ''      "*";
            default $http_origin;
        }
    
        server {
            …
            location /git/api {
                if ( $request_method = OPTIONS ) {
                    add_header Access-Control-Allow-Origin $allow_origin;
                    add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
                 …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@tYYGH
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by LinusBorg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants