美文网首页
vue本地调试dev代理

vue本地调试dev代理

作者: ljt001 | 来源:发表于2023-07-05 16:18 被阅读0次

注意:对于domain=.foo-t.example.com的cookie,在浏览器访问dev.foo-t.example.com:81发出http请求时,也会带上此cookie,虽然dev.foo-t.example.com:81和foo-t.example.com由于端口不一样而不算是同源域,但浏览器支持发送cookie。
比如cookie名称为foo_session,cookie的domain=.foo-t.example.com。

下面proxy代理主要作用是把对本地api的请求转为指定api:
比如向https://dev.foo-t.example.com:81/api/foo/name发出的请求,代理转发为向https://foo-t.example.com/api/foo/name请求。
又或向https://dev.foo-t.example.com:81/api/foo/name发出的请求,代理转发为向http://localhost:8001/foo/name请求,见下面注释掉的localhost转发规则。

vue.config.js内容:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  publicPath: '/zar',
  lintOnSave: false,
  transpileDependencies: true,
  devServer: {
    host: 'dev.foo-t.example.com',
    https: true,
    port: '81',
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      // 测试api
      '/api': {
        target: 'https://foo-t.example.com/',
        changeOrigin: true,
      },
      // // 假设本地api没有目录
      // '/api': {
      //   target: 'http://localhost:8001/',
      //   changeOrigin: true,
      //   pathRewrite: {
      //     '^/api': '',
      //   },
      // },
    },
  },
})

相关文章

网友评论

      本文标题:vue本地调试dev代理

      本文链接:https://www.haomeiwen.com/subject/kcekudtx.html