Vivek m
Vivek m

Reputation: 55

Hosting angular application with proxy configuration

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

Upvotes: 1

Views: 1990

Answers (1)

Ankit Sharma
Ankit Sharma

Reputation: 1704

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;
      }
    }

Upvotes: 1

Related Questions