美文网首页
解决 Nuxt 本地开发跨域、referer、origin 问题

解决 Nuxt 本地开发跨域、referer、origin 问题

作者: 梧桐月明中 | 来源:发表于2020-12-28 17:18 被阅读0次

    跨域问题,通过 @nuxtjs/proxy 解决

    // nuxt.config.js
    modules: [
        '@nuxtjs/proxy'
      ],
    
      proxy: [
        [
          '/api/',
          {
            target: 'siteexample.com'
          }
        ],
        [
          '/oauth2.0/',
          {
            target: 'siteexample.com'
          }
        ]
      ]
    

    referer 或 origin 问题,通过本地配置 host 解决

    注意配 host 不包含端口号

    // hosts
    192.168.0.43 m.siteexample.com
    

    nuxt 本地运行的 host 和 port 可在 package.json 中设置更改

    // package.json
    {
      "config": {
        "nuxt": {
          "host": "192.168.0.43",
          "port": "8980"
        }
      }
    }
    

    现在浏览器打开地址为 m.siteexample.com:8980/

    相关文章

      网友评论

          本文标题:解决 Nuxt 本地开发跨域、referer、origin 问题

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