亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

webpack開(kāi)發(fā)跨域問(wèn)題解決辦法

 更新時(shí)間:2017年08月03日 11:02:57   作者:mjzhang1993  
本篇文章主要介紹了webpack開(kāi)發(fā)跨域問(wèn)題解決辦法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

本文介紹了webpack開(kāi)發(fā)跨域問(wèn)題解決辦法,分享給大家,具體如下:

1. 說(shuō)明

webpack 內(nèi)置了 http-proxy-middleware 可以解決 請(qǐng)求的 URL 代理的問(wèn)題

2. API

需要代理的 pathname 要加 /

module.exports = {
  devtool: 'cheap-module-source-map',
  entry: './app/js/index.js'
  output: {
    path: path.resolve(__dirname, 'dev'),
    // 所有輸出文件的目標(biāo)路徑
    filename: 'js/bundle.js',
    publicPath: '/',
    chunkFilename: '[name].chunk.js'
  },
  devServer: {
    contentBase: path.resolve(__dirname, 'dev'),
    publicPath: '/',
    historyApiFallback: true,
    proxy: {
      // 請(qǐng)求到 '/device' 下 的請(qǐng)求都會(huì)被代理到 target: http://debug.xxx.com 中
      '/device/*': { 
        target: 'http://debug.xxx.com',
        secure: false, // 接受 運(yùn)行在 https 上的服務(wù)
        changeOrigin: true
      }
    }
  }
}

3. 使用

注:使用的url 必須以/開(kāi)始 否則不會(huì)代理到指定地址

  fetch('/device/space').then(res => {
    // 被代理到 http://debug.xxx.com/device/space
    return res.json();
  }).then(res => {
    console.log(res);
  })

  fetch('device/space').then(res => {
    // http://localhost:8080/device/space 訪(fǎng)問(wèn)本地服務(wù)
    return res.json();
  }).then(res => {
    console.log(res);
  })

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論