1

I am building a dictionary application using angular which uses oxford dictionary API to retrieve the data . In the development environment I have used proxy.conf.json to forward the requests.This is my proxy.conf.json file

{
"/oxfordapi": {
  "target": "https://od-api.oxforddictionaries.com/api/v1/entries/en/",
  "secure": true,
  "changeOrigin": true,
  "logLevel": "debug",
  "headers": {
    "Accept": "application/json",
    "app_id": "cb35ef20",
    "app_key": "603be016c344650e6d8c1da15330f7af"
  },
  "pathRewrite": {"^/oxfordapi" : ""}
 }
}

When I build the application for the production version and host it on my nginx server it always gives error when i try to get data from the server. I have read proxy_pass in nginx server config can be used but I am newbie to nginx server please help me fix this problem. If possible give the full server configuration for this issue .Thanks in advance

2
  • Can you share your current NGINX configuration? Commented Jul 17, 2018 at 4:25
  • server{ root /home/ubuntu/test/dist/demo; index index.html; server_name test.vivekm.me; location / { try_files $uri $uri/ /index.html; } } Commented Jul 17, 2018 at 4:53

1 Answer 1

1

Try the below code:-

server {

      root /home/ubuntu/test/dist/demo; 
      index index.html; 
      server_name test.vivekm.me; 

      location /oxfordapi {
        proxy_pass https://od-api.oxforddictionaries.com/api/v1/entries/en/;
        proxy_set_header Accept application/json;
        proxy_set_header app_id $http_app_id;
        proxy_set_header app_key $http_app_key;
      }

      location / {
            try_files $uri $uri/ /index.html;
      }
    }
Sign up to request clarification or add additional context in comments.

12 Comments

I need to send the headers also "headers": { "Accept": "application/json", "app_id": "cb35ef20", "app_key": "603be016c344650e6d8c1da15330f7af" }
Please try the updated answer and let me know the results. Thanks
Still I get the error as authentication parameters are missing
Are the app_id and app_key sent from the front end?
No they are set in proxy.conf.json
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.