const Proxy = require('http-proxy-middleware')

// https://github.com/chimurai/http-proxy-middleware

module.exports = function nuxtProxy (options) {
  if (!this.options.proxy) {
    // No proxy defined
    return
  }

  // Defaults
  const defaults = Object.assign({
    // Needed for virtual hosted sites
    changeOrigin: true,
    // Proxy webSockets
    ws: true
  }, options)

  delete defaults.src

  // Normalize options.proxy to middleware arguments
  const applyDefaults = o => Object.assign({}, defaults, o)
  const normalizeTarget = o => typeof o === 'object' ? o : { target: o }

  const proxy = []
  if (Array.isArray(this.options.proxy)) {
    // Array mode
    this.options.proxy.forEach(p => {
      if (Array.isArray(p)) {
        proxy.push([p[0], applyDefaults(normalizeTarget(p[1]))])
      } else {
        proxy.push([p, applyDefaults()])
      }
    })
  } else {
    // Object mode
    Object.keys(this.options.proxy).forEach(context => {
      proxy.push([context, applyDefaults(normalizeTarget(this.options.proxy[context]))])
    })
  }

  // Register middleware
  proxy.forEach(args => {
    this.options.serverMiddleware.push(Proxy.apply(undefined, args))
  })
}

module.exports.meta = require('./package.json')

@@ -1117,28 +1117,15 @@
     
-this.options.serverM
+const m
 iddl
@@ -1129,22 +1129,19 @@
 ddleware
-.push(
+ = 
 Proxy.ap
@@ -1160,16 +1160,121 @@
 d, args)
+%0A    middleware.prefix = false // Don't add router base%0A    this.options.serverMiddleware.push(middleware
 )%0A  %7D)%0A%7D

disable prefix