Search code examples
angularjsionic-frameworkcorsmeanjs

How do I setup reverse proxy on nginx to avoid the CORS issue for my ionic and meanjs application.


So I have 2 apps running on same server. 1. On backend I have Mean.js which provides the services to perform CRUD operations. 2. On front end I'm using IONIC app which provides the UI experience.

Front end ( Ionic app ) is running on 81 and Backend on 3000.

I tried to setup reverse proxy for backend ( node/ mean ) by looking up online but didnt succeed.

Here's my nginx setup

server {
    listen 80;

    server_name meantodo.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        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;
    }
} 

enter image description here


Solution

  • Resolved it by adding following lines on https://github.com/meanjs/mean/blob/master/config/lib/express.js#L57

    var corsOptions = {
        origin: 'http://34.192.250.412:80',
        optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
      };
      app.use(cors());