跨域

184 阅读1分钟
第一种方法
devServer: {
    proxy: {
      '/api': {
          target: 'https://localhost:8000',
          secure: false,//true 以https开头
          pathRewrite: {
              '^/api': ""
          },
          changeOrigin: true,//把请求头中的host改成服务器的地址
      }
  }
}
第二种方法
devServer: {
    before: function(app, server) {
    	app.get('api/user',function(req, res) {
            res.json({custom: 'response'})
        })
    }
}