add request support

yhy
FrozenArcher 2024-03-06 14:04:17 +08:00
parent 7d7d8df7d3
commit 5f2e66546c
7 changed files with 136 additions and 22 deletions

View File

@ -1,2 +1,4 @@
# 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config
TARO_APP_ID="wx636eb7cf2b84f305"
TARO_APP_API="http://127.0.0.1:9527"
TARO_APP_API_OREO="http://127.0.0.1:9527"

View File

@ -1 +1,3 @@
TARO_APP_ID="wx636eb7cf2b84f305"
TARO_APP_API=""
TARO_APP_API_OREO=""

View File

@ -1,5 +1,8 @@
export default {
'GET /api/user/1': {},
'POST /api/upload': {},
'GET /testdata': {
success: true,
data: {
test: 'test',
},
},
};

74
package-lock.json generated
View File

@ -12,7 +12,6 @@
"@tarojs/components": "3.6.24",
"@tarojs/helper": "3.6.24",
"@tarojs/plugin-framework-react": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-alipay": "3.6.24",
"@tarojs/plugin-platform-harmony-hybrid": "3.6.24",
"@tarojs/plugin-platform-jd": "3.6.24",
@ -24,6 +23,7 @@
"@tarojs/runtime": "3.6.24",
"@tarojs/shared": "3.6.24",
"@tarojs/taro": "3.6.24",
"process": "^0.11.10",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"taro-ui": "^3.3.0"
@ -32,6 +32,7 @@
"@babel/core": "^7.8.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@tarojs/cli": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-h5": "^3.6.24",
"@tarojs/taro-loader": "3.6.24",
"@tarojs/test-utils-react": "^0.1.1",
@ -54,6 +55,7 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^15.2.2",
"mockjs": "^1.1.0",
"postcss": "^8.4.18",
"react-refresh": "^0.11.0",
"stylelint": "^14.4.0",
@ -8842,6 +8844,7 @@
"version": "0.0.9",
"resolved": "https://registry.npmmirror.com/@tarojs/plugin-mock/-/plugin-mock-0.0.9.tgz",
"integrity": "sha512-Q4z4lHp2mHVByQJ8gtIq0Rct8vkEqvCmyTmv+EJNf9sJY3F5H1fmDNfgMVn2fyZj7TmxuSMq/FDtgNlEA4eTow==",
"dev": true,
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
@ -8856,17 +8859,16 @@
"version": "5.1.1",
"resolved": "https://registry.npmmirror.com/get-port/-/get-port-5.1.1.tgz",
"integrity": "sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==",
"dev": true,
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@tarojs/plugin-mock/node_modules/http-proxy-middleware": {
"version": "1.3.1",
"resolved": "https://registry.npmmirror.com/http-proxy-middleware/-/http-proxy-middleware-1.3.1.tgz",
"integrity": "sha512-13eVVDYS4z79w7f1+NPllJtOQFx/FdUW4btIvVRMaRlUY9VGstAbo5MOhLEuUgZFRHn3x50ufn25zkj/boZnEg==",
"dev": true,
"dependencies": {
"@types/http-proxy": "^1.17.5",
"http-proxy": "^1.18.1",
@ -8882,17 +8884,16 @@
"version": "3.0.0",
"resolved": "https://registry.npmmirror.com/is-plain-obj/-/is-plain-obj-3.0.0.tgz",
"integrity": "sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==",
"dev": true,
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@tarojs/plugin-mock/node_modules/path-to-regexp": {
"version": "6.2.1",
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz",
"integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw=="
"integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==",
"dev": true
},
"node_modules/@tarojs/plugin-platform-alipay": {
"version": "3.6.24",
@ -9694,6 +9695,7 @@
"version": "1.17.14",
"resolved": "https://registry.npmmirror.com/@types/http-proxy/-/http-proxy-1.17.14.tgz",
"integrity": "sha512-SSrD0c1OQzlFX7pGu1eXxSEjemej64aaNPRhhVYUGqXh0BtldAAx37MG8btcumvpgKyZp1F5Gn3JkktdxiFv6w==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
@ -11062,7 +11064,8 @@
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"dev": true
},
"node_modules/array-includes": {
"version": "3.1.7",
@ -13628,6 +13631,7 @@
"version": "0.5.4",
"resolved": "https://registry.npmmirror.com/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
"dev": true,
"dependencies": {
"safe-buffer": "5.2.1"
},
@ -13652,6 +13656,7 @@
"version": "0.5.0",
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.5.0.tgz",
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==",
"dev": true,
"engines": {
"node": ">= 0.6"
}
@ -13659,7 +13664,8 @@
"node_modules/cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmmirror.com/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
"dev": true
},
"node_modules/copy-anything": {
"version": "2.0.6",
@ -13858,6 +13864,7 @@
"version": "2.8.5",
"resolved": "https://registry.npmmirror.com/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dev": true,
"dependencies": {
"object-assign": "^4",
"vary": "^1"
@ -16697,7 +16704,8 @@
"node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmmirror.com/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==",
"dev": true
},
"node_modules/events": {
"version": "3.3.0",
@ -17426,6 +17434,7 @@
"version": "4.18.3",
"resolved": "https://registry.npmmirror.com/express/-/express-4.18.3.tgz",
"integrity": "sha512-6VyCijWQ+9O7WuVMTRBTl+cjNNIzD5cY5mQ1WM8r/LEkI2u8EYpOotESNwzNlyCn3g+dmjKYI6BmNneSr/FSRw==",
"dev": true,
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
@ -17467,6 +17476,7 @@
"version": "2.6.9",
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"dependencies": {
"ms": "2.0.0"
}
@ -17474,17 +17484,20 @@
"node_modules/express/node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"dev": true
},
"node_modules/express/node_modules/path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmmirror.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ=="
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==",
"dev": true
},
"node_modules/express/node_modules/qs": {
"version": "6.11.0",
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.11.0.tgz",
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
"dev": true,
"dependencies": {
"side-channel": "^1.0.4"
},
@ -17865,6 +17878,7 @@
"version": "1.2.0",
"resolved": "https://registry.npmmirror.com/finalhandler/-/finalhandler-1.2.0.tgz",
"integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==",
"dev": true,
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
@ -17882,6 +17896,7 @@
"version": "2.6.9",
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"dependencies": {
"ms": "2.0.0"
}
@ -17889,7 +17904,8 @@
"node_modules/finalhandler/node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"dev": true
},
"node_modules/find-babel-config": {
"version": "1.2.0",
@ -18095,6 +18111,7 @@
"version": "1.15.5",
"resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.5.tgz",
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
"dev": true,
"funding": [
{
"type": "individual",
@ -18187,6 +18204,7 @@
"version": "0.2.0",
"resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"dev": true,
"engines": {
"node": ">= 0.6"
}
@ -19358,6 +19376,7 @@
"version": "1.18.1",
"resolved": "https://registry.npmmirror.com/http-proxy/-/http-proxy-1.18.1.tgz",
"integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
"dev": true,
"dependencies": {
"eventemitter3": "^4.0.0",
"follow-redirects": "^1.0.0",
@ -24533,7 +24552,8 @@
"node_modules/merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w=="
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==",
"dev": true
},
"node_modules/merge-options": {
"version": "3.0.4",
@ -24591,6 +24611,7 @@
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/methods/-/methods-1.1.2.tgz",
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
"dev": true,
"engines": {
"node": ">= 0.6"
}
@ -26347,6 +26368,18 @@
"resolved": "https://registry.npmmirror.com/mobile-detect/-/mobile-detect-1.4.5.tgz",
"integrity": "sha512-yc0LhH6tItlvfLBugVUEtgawwFU2sIe+cSdmRJJCTMZ5GEJyLxNyC/NIOAOGk67Fa8GNpOttO3Xz/1bHpXFD/g=="
},
"node_modules/mockjs": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/mockjs/-/mockjs-1.1.0.tgz",
"integrity": "sha512-eQsKcWzIaZzEZ07NuEyO4Nw65g0hdWAyurVol1IPl1gahRwY+svqzfgfey8U8dahLwG44d6/RwEzuK52rSa/JQ==",
"dev": true,
"dependencies": {
"commander": "*"
},
"bin": {
"random": "bin/random"
}
},
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
@ -29237,6 +29270,14 @@
"node": ">=4"
}
},
"node_modules/process": {
"version": "0.11.10",
"resolved": "https://registry.npmmirror.com/process/-/process-0.11.10.tgz",
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
@ -29313,6 +29354,7 @@
"version": "2.0.7",
"resolved": "https://registry.npmmirror.com/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"dev": true,
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
@ -29325,6 +29367,7 @@
"version": "1.9.1",
"resolved": "https://registry.npmmirror.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"dev": true,
"engines": {
"node": ">= 0.10"
}
@ -31170,6 +31213,7 @@
"version": "5.2.1",
"resolved": "https://registry.npmmirror.com/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"dev": true,
"funding": [
{
"type": "github",

View File

@ -20,7 +20,7 @@
"build:jd": "taro build --type jd",
"build:quickapp": "taro build --type quickapp",
"build:harmony-hybrid": "taro build --type harmony-hybrid",
"dev:weapp": "npm run build:weapp -- --watch",
"dev:weapp": "npm run build:weapp -- --watch --mode dev",
"dev:swan": "npm run build:swan -- --watch",
"dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch",
@ -44,7 +44,6 @@
"@tarojs/components": "3.6.24",
"@tarojs/helper": "3.6.24",
"@tarojs/plugin-framework-react": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-alipay": "3.6.24",
"@tarojs/plugin-platform-harmony-hybrid": "3.6.24",
"@tarojs/plugin-platform-jd": "3.6.24",
@ -56,6 +55,7 @@
"@tarojs/runtime": "3.6.24",
"@tarojs/shared": "3.6.24",
"@tarojs/taro": "3.6.24",
"process": "^0.11.10",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"taro-ui": "^3.3.0"
@ -64,6 +64,7 @@
"@babel/core": "^7.8.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@tarojs/cli": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-h5": "^3.6.24",
"@tarojs/taro-loader": "3.6.24",
"@tarojs/test-utils-react": "^0.1.1",
@ -86,6 +87,7 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^15.2.2",
"mockjs": "^1.1.0",
"postcss": "^8.4.18",
"react-refresh": "^0.11.0",
"stylelint": "^14.4.0",

View File

@ -2,6 +2,7 @@
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "EVA-Notify",
"setting": {
"compileHotReLoad": true
"compileHotReLoad": true,
"urlCheck": false
}
}

View File

@ -0,0 +1,60 @@
import process from 'process';
/**
* Get URL of backend
* @param path Relative path to base url, begins with `/`
* @returns Full url
*
* @example
*
* ``` tsx
* import { getUrl } from '@/service';
* import { Component, ReactNode } from 'react';
* import Taro from '@tarojs/taro';
*
* class Index extends Component {
* state = {
* testData: {},
* }
* componentDidMount(): void {
* Taro.request({
* url: getUrl('/testdata'),
* method: 'GET',
* }).then(res => {
* console.log(res.data);
* this.setState({ testData: res.data.data });
* });
* }
* render() { ... }
* }
* ```
*/
export function getUrl(path: string): string {
const baseUrl = process.env.TARO_APP_API;
// console.log('bu:', baseUrl);
if (baseUrl) {
return baseUrl + path;
} else {
console.log('env TARO_APP_API is undefined');
return '';
}
}
/**
* Get URL of Oreo backend
* @param path Relative path to base url, begins with `/`
* @returns Full url
*
* @example
* // see example of `getUrl`
*/
export function getUrlOreo(path: string): string {
const baseUrlOreo = process.env.TARO_APP_API_OREO;
// console.log('buo:', baseUrlOreo);
if (baseUrlOreo) {
return baseUrlOreo + path;
} else {
console.log('env TARO_APP_API_OREO is undefined');
return '';
}
}