网站首页 文章专栏 webpack proxy 基础验证(auth)
不废话,直接上示例:
devServer: { host: '127.0.0.1', port: 8088, proxy: { '/api/': { target: 'http://127.0.0.1:8080', changeOrigin: true, auth: "admin:admin", // pathRewrite: { // '^/api': '' // } } },
记得加 引号 "admin:admin"
不然,就会报错:
SyntaxError: Unexpected token :
at Module._compile (internal/modules/cjs/loader.js:872:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
......