$ .get在调用其他API后停止工作(使用nginx)

时间:2015-11-11 15:52:07

标签: jquery json node.js api nginx

我在nginx服务器下运行了两个API

客户端代码

function loadBlog(session){
     if(checkSession(session){
        $.get( "/api/blogindex", function(returnData){ 
            $('#mainContainer').html(Handlebars.getTemplate('blogindex')({blogList: returnData.blogList}));
        });
        }else{
            $.get( "/api/unsecure/blogindex", function(returnData) { 
            $('#mainContainer').html(Handlebars.getTemplate('blogindex')({blogList: returnData.blogList}));
            });    
        }; 

Nginx.conf

      location / {
                    root /Users/project/get_buged;
                    try_files $uri /index.html;

            }

            location /api { # this is our api 
                 rewrite /api/?(.*)$ /$1 redirect;
           # rewrite /api/(.*) /$1 break;
        add_header Access-Control-Allow-Origin *;
                    proxy_pass http://localhost:8080;
                    proxy_pass_request_headers on;
                    proxy_pass_request_body on;
        proxy_redirect off;
        proxy_set_header Host $host;

            }

            location /upload { # this is upload handler

          rewrite /upload/?(.*)$ /$1 redirect;
        # rewrite /upload/(.*) /$1 break;
        add_header Access-Control-Allow-Origin *;
                    proxy_pass http://localhost:3000;
                    proxy_pass_request_headers on;
                    proxy_pass_request_body on;
        proxy_redirect off;
                    proxy_set_header Host $host;


            }
    }

例如

如果我只向第一个api发送JSON请求,一切正常,但我决定将JSON请求发送到第二个api,我再也无法通过json请求(客户端)访问我的第一个api,直到我再次登录。

这样的事件链:调用json数据API第一 - >得到数据 - >调用json数据API第二 - >得到数据 - >再次调用API第一 - >我从服务器获得302重定向响应,当然没有json数据,我再也无法访问json数据的第一个API

我做错了什么?我只能使用一个api,否则我的api会以某种方式变得怪异

0 个答案:

没有答案