简体   繁体   中英

vue-cli devServer proxy bypass

I would like Vue CLI's dev server to return a string when a specific URL is fetched. For this, I wanted to use webpack dev-server 's bypass option. (webpack docs )

I tried this:

devServer: {
    proxy: {
        '/something': {
            bypass: (req, res) => res.send(process.env.SOMETHING),
        }
    }
}

This causes an error: When proxy in package.json is an object, each context object must have a target property specified as a url string .

I don't need a target option (like in this example )

How can I make this work?

devServer.proxy isn't appropriate for this. Instead, add your route in devServer.before :

// vue.config.js
module.exports = {
  devServer: {
    before(app) {
      app.get('/something', (req, res) => res.send(process.env.SOMETHING))
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM