You cannot assign a function as the path value, as that value is parsed as a URL. See here.
Instead, what you can do is intercept the requests before it hits the router, start your services as needed, and then forward the request back to the router:
var init = function(req, res, next){
if(req.url.indexOf('task1') > -1 && !serviceIsRunning()){
startService();
next(); // forward req back to router
} else {
// no need to do anything, move request along
next();
}
}
httpProxy.createServer('localhost', options, init).listen(80);