gruntjs / grunt-contrib-connect

Start a static web server.
http://gruntjs.com
MIT License
714 stars 145 forks source link

Connect to subfolder of a server #111

Closed starangelam closed 10 years ago

starangelam commented 10 years ago

Hi I'm very confused right now if this is possible:

I'm using this plugin in conjunction with grunt-connect-proxy as middleware to proxy my local setup to work with a remote backend to go around same-origin error.

My problem is my request must be proxy to the subdirectory exactly. I can't go into my front-end to append this all over my code base, as the remote backend change from setup to setup, next one most likely will not have this subdirectory problem.

Below is the full grunt setup

connect: {
  server: {
    options: {
      port: 3007,
        hostname: 'localhost',
        keepalive: true,
        appendProxies: false,
        // This middleware function ensures all requests go through the proxies
        middleware: function(connect) {
        var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
        return [proxySnippet];
      }
    },
    proxies: [
      {
        //  send backend request to remote server
        host: 'remote.server.com/subdirectory/',
        port: '80', // optional 
        context: '/cortex'  // this value sends all request from this SF that starts with /cortex to host above
      },
      {
        // this is my local served by nodejs on port 3008
        context: '/',
        host: 'localhost',
        port: 3008,
        // This rewrite allows the app to be accessed at:
        // http://localhost:3007/ AND http://localhost:3007/html5storefront/
        rewrite: {
          '^/html5storefront/': '/'
        }
      }
    ]
  }
}

Thanks a lot for help!

a.

jamesplease commented 10 years ago

Questions should be asked on StackOverflow

;)