0
votes

I'm trying to configure Apache using mod_proxy to develop a Dart web app locally, but I can't seem to get it set up correctly.

In my httpd.conf I've enabled the following lines:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Include conf/extra/httpd-vhosts.conf

In httpd-vhosts.conf I tried to set up what I needed, but it doesn't seem to be working. I've got a spring web app I'm running from Eclipse with Jetty. So that is on http://localhost:8080. Then I run Dart from the Dart Editor, and it ends up being on 127.0.0.1:3030 (although the total path of a request like "login" is: http://127.0.0.1:3030/C:/Users/CorayThan/dart/BlightedRealmUi/web/out/login).

Either way, I'm trying to get apache to redirect my requests from 127.0.0.1:3030 to localhost:8080. I've tried to do that like this in httpd-vhosts.conf:

<VirtualHost *:80>
    ServerAdmin test@localhost
    ServerName 127.0.0.1:3030

    ProxyPass / http://localhost:8080
    ProxyPassReverse / http://localhost:8080

    ErrorLog "logs/proxy-error.log"
</VirtualHost>

But it doesn't seem to be working at all. Can anyone suggest how I can fix it, or suggest a better way to do this in the first place? (I don't want to use CORS or Jsonp, I just want an easy cross-browser compatible hack for development.)

2

2 Answers

1
votes

I'm not sure you can do this, your VHost would have to listen on 3030, not 80 as you have above to perform the proxy function which it can't do as Dart is using this port, below is an extract from a Vhost file I use to proxy from Dartium to a CouchDb server to allow a browser based couchdb client access using CORS, this may not be what you want though :-

<VirtualHost *:8080>
    <Proxy http://141.196.22.210:5984>
        Order deny,allow
        Allow from all 
    </Proxy> 
    RewriteEngine on
    RewriteCond %{REQUEST_METHOD} ^OPTIONS
    Header set Access-Control-Allow-Origin http://127.0.0.1:3030
    Header set Access-Control-Allow-Credentials true
    Header set Access-Control-Allow-Headers Content-Type
    Header merge Access-Control-Allow-Headers Authorization
    Header merge Access-Control-Allow-Headers Destination
    Header set Access-Control-Allow-Methods GET
    Header merge Access-Control-Allow-Methods POST
    Header merge Access-Control-Allow-Methods PUT 
    Header merge Access-Control-Allow-Methods OPTIONS
    Header merge Access-Control-Allow-Methods DELETE 
    Header merge Access-Control-Allow-Methods HEAD 
    Header merge Access-Control-Allow-Methods COPY
    Header set Access-Control-Max-Age 3600 

    ProxyRequests off
    ProxyPreserveHost Off
    KeepAlive Off

    ProxyPass / http://141.196.22.210:5984/ nocanon
    ProxyPassReverse / http://141.196.22.210:5984/
</VirtualHost>

So, when my client app logs in to Couch it uses 141.196.22.210:8080.

1
votes

I had the same problem and I solved it by creating a virtual host with a proxy for both tomcat and for the dart application. Roughly, here is my virtual host:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName dartapp

    <Location "/tomcat-application-context/">
        ProxyPass "http://localhost:8080/tomcat-application-context/"
        ProxyPassReverse "http://localhost:8080/tomcat-application-context/"
    </Location>
    <Location "/dart/">
        ProxyPass "http://127.0.0.1:3030/"
        ProxyPassReverse "http://127.0.0.1:3030"
    </location>
</VirtualHost>

Normally when you "Run in Dartium" you'll access the app with the full path to your dart app:

http://127.0.0.1:3030/full/path/to/web/app.html

Instead, access your apache virtual host with your /full/path/to/web/app.html prefixed with your proxy location (i.e. /dart/full/path/to/web/app.html):

http://dartapp:80/dart/full/path/to/web/app.html