Project Feature: Proxy Forwarding
When configuring a project, Maque supports the ability to forward all unmatched incoming requests to a remote URL. This feature allows you to run your entire application through Maque and then only capture requests that match your existing Services and Rules.
For more detailed information about Data Services, Methods, Rules and Arguments please refer to these other articles:
- Data Services Overview
- Services And Methods
- Proxy Rules
- Incoming Request Capture Wizard
Configure the Project
When creating a new project or editing a project configuration (File > Update Project Configuration...) you have the ability to enable the Proxy and define a remote URL. By default, this feature is disabled and any unmatched incoming request will have the Maque server return a 404.
When the project has the proxy enabled and the Maque server is running, any incoming request that does not match an existing Rule will be forwarded to the defined remote URL and the response from the remote server will be returned back to the requester.
Hosting an application with Proxy Rules
In a standard Maque project, you may configure you application to only send API requests to Maque. For example, a basic Ajax driven web application will be hosted by a web server. You would then modify the Ajax url path to request all calls through Maque. This allows you to stub out the Ajax calls in Maque and still have the web app hosted from your server of choice.
To support this configuration, Maque provides Cross Origin (CORS) support to allow modern browsers to route Ajax calls through the Maque server, even though the application was hosted from a different location. This ability covered many application scenarios but when requiring cookie session and authentication this process prevents applications from working correctly, especially with Proxy Rules.
The challenge with standard process is that the application is being hosted from one server (ex: http://myapp.dev) but the Ajax calls are being sent to Maque (http://localhost:5656). When using Proxy Rules, the incoming requests are forwarded back to the remote server, http://myapp.dev, and the outbound proxy request will not have any of the authentication header information because the target remote service is a different source (i.e. The app called the host localhost:5656 but the server session is bound to the host myapp.dev).
To enable authentication and cookie support all calls and requests need to come from the same domain host. This is where the Proxy Forward feature comes into play. Instead of calling your dev server in the browser (http://myapp.dev) and changing the Ajax calls to point to Maque, you can configure the Proxy Forward to point to your dev server and then call the Maque server directly from the browser (http://localhost:5656).
When the browser loads http://localhost:5656 all unmatched requests (i.e. no matching Service/Rules) will be forwarded to the Proxy URL. The browser now considers all calls coming from the same source and headers and sessions are managed properly. You can then easily use Proxy Rules and the Incoming Request Capture Wizard to cherry-pick which services should be handled by Maque and all other requests will be forwarded to the server.