@ywfe/fe-tools 1.2.1-beta.34 → 1.2.1-beta.35
Sign up to get free protection for your applications and to get access to all the features.
- package/handler.ts +3 -0
- package/index.ts +1 -2
- package/lib/handler.d.ts +2 -0
- package/lib/index.d.ts +1 -2
- package/lib/userInputToJson.d.ts +1 -5
- package/lib/ywfe-tools.cjs +10 -8725
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +10 -8724
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/package.json +1 -1
- package/userInputToJson.ts +11 -15
- package/JSON2String.ts +0 -14
- package/lib/JSON2String.d.ts +0 -7
- package/lib/request.d.ts +0 -9
- package/lib/ywfe-tools.umd.js +0 -4
- package/lib/ywfe-tools.umd.js.map +0 -1
- package/request.ts +0 -48
package/request.ts
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
// Ctrl-S保存代码
|
2
|
-
import { querystring } from "@ywfe/utils";
|
3
|
-
interface RequestOptions {
|
4
|
-
url: string;
|
5
|
-
method?: string;
|
6
|
-
params?: any;
|
7
|
-
}
|
8
|
-
async function request({ input }: { input: RequestOptions }) {
|
9
|
-
const method = input.method || "GET";
|
10
|
-
const basePathMap = new Map([
|
11
|
-
["prod", "https://gateway.ywwl.com"],
|
12
|
-
["test", "https://test-gateway.ywwl.com"],
|
13
|
-
["test2", "https://test2-gateway.ywwl.com"],
|
14
|
-
["dev", "https://dev-gateway.ywwl.com"],
|
15
|
-
]);
|
16
|
-
const getBasePath = () => {
|
17
|
-
const env = "{{env}}";
|
18
|
-
return basePathMap.get(env);
|
19
|
-
};
|
20
|
-
const isValidURL = (url:string) => {
|
21
|
-
const regex = /^https?:\/\//;
|
22
|
-
return regex.test(url);
|
23
|
-
};
|
24
|
-
const prefix = getBasePath();
|
25
|
-
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
26
|
-
console.log('requestUrl',requestUrl,isValidURL(input.url))
|
27
|
-
const fetchOption: { [key: string]: any } = {
|
28
|
-
method: method,
|
29
|
-
headers: {
|
30
|
-
"Content-type": "application/json",
|
31
|
-
"x-token": "{{token}}",
|
32
|
-
},
|
33
|
-
};
|
34
|
-
if (method.toUpperCase() === "POST") {
|
35
|
-
fetchOption.body = JSON.stringify(input.params);
|
36
|
-
} else if (method.toUpperCase() === "GET") {
|
37
|
-
requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`;
|
38
|
-
}
|
39
|
-
const response = await fetch(requestUrl, fetchOption);
|
40
|
-
if (!response.ok) {
|
41
|
-
const message = `An error has occured: ${response.status}`;
|
42
|
-
return { success: false, message };
|
43
|
-
}
|
44
|
-
const result = await response.json();
|
45
|
-
return result;
|
46
|
-
}
|
47
|
-
|
48
|
-
export default request
|