     webRoot = grunt.config.get("server.base") || "generated"
     userConfig = fileUtils.loadConfigurationFile("server")
     pushStateEnabled = grunt.config.get("server.pushState")
+    @requiresConfig("server.apiProxy.prefix") if pushStateEnabled
     app = express()
 
     userConfig.drawRoutes(app) if userConfig.drawRoutes
 
     app.configure ->
       app.use express.static("#{process.cwd()}/#{webRoot}")
-      app.use apiProxy(apiProxyPrefix, apiProxyHost, apiPort, new httpProxy.RoutingProxy()) if apiProxyEnabled
+
+      if apiProxyEnabled and pushStateEnabled
+        app.use prefixMatchingApiProxy(apiProxyPrefix, apiProxyHost, apiPort, new httpProxy.RoutingProxy())
+        grunt.log.writeln("Proxying API requests prefixed with '#{apiProxyPrefix}' to #{apiProxyHost}:#{apiPort}")
+      else
+        if apiProxyEnabled
+          app.use apiProxy(apiProxyHost, apiPort, new httpProxy.RoutingProxy())
+          grunt.log.writeln("Proxying API requests to #{apiProxyHost}:#{apiPort}")
+
       app.use express.errorHandler()
       app.use pushStateSimulator(process.cwd(),webRoot) if pushStateEnabled
 
     grunt.log.writeln("Starting express web server in \"./generated\" on port #{webPort}")
-    grunt.log.writeln("Proxying API requests to #{apiProxyHost}:#{apiPort}") if apiProxyEnabled
-    grunt.log.writeln("Simulating HTML5 PushState: Serving up '#{webRoot}/index.html' for all other unmatched paths") if pushStateEnabled
+    grunt.log.writeln("Simulating HTML5 pushState: Serving up '#{webRoot}/index.html' for all other unmatched paths") if pushStateEnabled
 
     app.listen webPort, ->
       resetRoutesOnServerConfigChange(app)

"apiProxy.port" - the port of the server running an API we want to proxy (does not proxy be default, can be overridden with ENV variable API_PORT)
"apiProxy.enabled" - set to true to enable API proxying; if Lineman can't respond to a request, it will forward it to the API proxy
"apiProxy.host" - the host to which API requests should be proxy, defaults to `localhost`)"
###
module.exports = (grunt) ->
  _ = grunt.util._

      grunt.log.writeln("\nPushState: '#{req.path}' not found in #{cwd}/#{webRoot} - Serving up '#{webRoot}/index.html'")
      res.sendfile("#{webRoot}/index.html")

  handleProxyError = (err, req, res) ->
    res.statusCode = 500
    res.write("API Proxying to `#{req.url}` failed with: `#{err.toString()}`")
    res.end()

  prefixMatchingApiProxy = (prefix, host, port, proxy) ->
    prefixMatcher = new RegExp(prefix)

    proxy.on "proxyError", handleProxyError

    return (req, res, next) ->
      if prefix and prefixMatcher.exec(req.path)
        proxy.proxyRequest(req, res, {host, port})
      else
        next()

  apiProxy = (host, port, proxy) ->
    proxy.on "proxyError", handleProxyError

    return (req, res, next) ->
      proxy.proxyRequest(req, res, {host, port})


  resetRoutesOnServerConfigChange = (app) ->
    watchr grunt.file.expand('config/server.*'), (err, watcher) ->
