The question is fairly easy to explain. I currently have two versions of my connect task, one that works with a grunt-contrib-proxy and the other that works with modRewrite. But I need to use both.
In this way, if a certain selection of 'routes' are loaded: ['/login', '/ord'] I need to proxy the request, but if anything else is loaded, I need to redirect to /index.html. The reason for this, is that I am using backbone.js, so localhost:8000/fun is supposed to load the fun route in backbone.
All of the following connect tasks are working perfectly (on their own).
TL;DR How can I combine these connect tasks:
connect: {
server: {
options: {
port: 9001,
middleware: function(connect, options) {
var middlewares, proxy;
proxy = require('grunt-connect-proxy/lib/utils').proxyRequest;
middlewares = [proxy, connect["static"](options.base), connect.directory(options.base)];
return middlewares;
}
},
proxies: [
{
context: ['/login', '/ord'],
host: '10.10.1.13',
https: false
}
]
}
}
connect: {
server: {
options: {
port: 9001,
open: true,
base: ['./'],
middleware: function(connect, options) {
var middlewares;
middlewares = [];
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']));
options.base.forEach(function(base) {
return middlewares.push(connect["static"](base));
});
return middlewares;
}
}
}
}
Here they are in coffee if you prefer:
connect:
server:
options:
port: 9001
# keepalive: true
middleware: (connect, options) ->
proxy = require('grunt-connect-proxy/lib/utils').proxyRequest
middlewares = [
proxy
connect.static(options.base)
connect.directory(options.base)
]
middlewares
proxies: [
{
context: ['/login', '/ord']
host: '10.10.1.13'
https: false
}
]
connect:
server:
options:
port: 9001
open: true
base: ['./']
middleware: (connect, options) -> (
middlewares = []
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']))
options.base.forEach( (base) ->
middlewares.push(connect.static(base))
)
middlewares
)
Thanks a bagillion.
This article was helpful in solving my issues.
Coffee Solution: