Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h5本地开发proxy代理保存 #16465

Open
15020254848 opened this issue Sep 5, 2024 · 1 comment
Open

h5本地开发proxy代理保存 #16465

15020254848 opened this issue Sep 5, 2024 · 1 comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@15020254848
Copy link

相关平台

H5

复现仓库

https://github.com/15020254848/h5_proxy.git
浏览器版本: chrome 128.0.6613.120
使用框架: React

复现步骤

使用的taro版本是3.3.31,

export default defineConfig(async (merge, { command, mode }) => {
  const baseConfig = {
      ···
      h5: {
         devServer: {
        proxy: [
          {
            context: ['/api'],
            target: 'https://aaa.ebanktest.com.cn:30061',
            changeOrigin: true,
            secure: false, // 忽略SSL验证
          },
        ],
        // proxy: {
        //   '/api': {
        //     // 使用正斜杠开头的字符串来匹配请求路径
        //     target: 'https://aaa.ebanktest.com.cn:30061',
        //     changeOrigin: true,
        //     secure: false, // 忽略SSL验证
        //   },
        // },
      },
      }
  }
}))

点击Hello world!调接口代理报错, Error occurred while proxying request

import { View, Text } from '@tarojs/components'
import Taro, { useLoad } from '@tarojs/taro'
import './index.scss'

export default function Index() {

  useLoad(() => {
    console.log('Page loaded.')
  })

  return (
    <View className='index'>
      <Text onClick={() => {
        Taro.request({
          url: '/api/hsjry/easyflow/trade/product/queryDetail',
          data:{},
          header: {
            'Content-Type': 'application/json',
          },
          method: "POST",
        })
      }}>Hello world!</Text>
    </View>
  )
}

期望结果

代理不保存

实际结果

[webpack-dev-server] [HPM] Error occurred while proxying request 10.104.114.99:10087/api/api/hsjry/easyflow/trade/product/queryDetail to https://aaa.com/ [EPROTO] (https://nodejs.org/api/errors.html#errors_common_system_errors)

环境信息

 Taro v3.6.31


  Taro CLI 3.6.31 environment info:
    System:
      OS: macOS 14.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
      Yarn: 1.22.19 - ~/.yarn/bin/yarn
      npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.31 => 3.6.31 
      @tarojs/components: 3.6.31 => 3.6.31 
      @tarojs/helper: 3.6.31 => 3.6.31 
      @tarojs/plugin-framework-react: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-alipay: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-h5: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-jd: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-qq: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-swan: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-tt: 3.6.31 => 3.6.31 
      @tarojs/plugin-platform-weapp: 3.6.31 => 3.6.31 
      @tarojs/react: 3.6.31 => 3.6.31 
      @tarojs/runtime: 3.6.31 => 3.6.31 
      @tarojs/shared: 3.6.31 => 3.6.31 
      @tarojs/taro: 3.6.31 => 3.6.31 
      @tarojs/taro-loader: 3.6.31 => 3.6.31 
      @tarojs/webpack5-runner: 3.6.31 => 3.6.31 
      babel-preset-taro: 3.6.31 => 3.6.31 
      eslint-config-taro: 3.6.31 => 3.6.31 
      react: ^18.0.0 => 18.3.1 


补充信息

h5本地开发、使用proxy代理报错

This was referenced Sep 7, 2024
@TheKonka TheKonka added V-3 Version - 3.x F-react Framework - React T-h5 Target - 编译到 H5 labels Sep 12, 2024
@y-not-u
Copy link

y-not-u commented Sep 30, 2024

我运行了你的项目,发现返回是 504 错误。

同时尝试访问你的 API 地址,应该是没有正确启动后端服务。

telnet aaa.ebanktest.com.cn 30061

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Status: Padding
Development

No branches or pull requests

3 participants