Error: Request failed with status code 405 , payload return HTML not JSON like intended

Viewed 121

I'm setting up a webapps using Node JS + React + NGINX on AWS and then when i want to access the url /auth

it return me some HTML code instead of JSON like i wanted to be i tested the code on LOCALHOST and it works fine

I tried to set the folder permission, because i think maybe user permission is the problem

I also tried editing some stuff on the Nginx.conf

below is my app.conf for the nginx

upstream webapp{
    server 127.0.0.1:3018;
}

server_names_hash_bucket_size 64;
server_names_hash_max_size 512;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name 127.0.0.1;
        server_name_in_redirect off; 

    if ($http_x_forwarded_proto = 'http'){
       return 301 https://$host$request_uri;
    }


   location / {
        root /home/website/client/build;
        try_files $uri /index.html;
        log_not_found off;
        access_log off;
    }

    #error_page  405     =200 $uri;

    if ( $http_user_agent ~* (nmap|nikto|wikto|sf|sqlmap|bsqlbf|w3af|acunetix|havij|appscan) ) {
        return 403;
    }
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block;";
    add_header Strict-Transport-Security "max-age=2592000; includeSubDomains" always;
}
action     {…}
​
payload: Object { isAuth: false, error: true }
​
type: "auth_member"

i expect the output code like this one but instead the web give me something else

1 Answers

you have to define the upstrem location to be proxed to:

 # this is an example you can modify the path on as you get it
 location /api {
       proxy_pass http://webapp;
       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;
    }


Related