@arena-ui/services 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/get_service.js +9 -0
- package/index.js +5 -0
- package/load_services.js +10 -0
- package/package.json +12 -0
- package/post_request.js +48 -0
package/get_service.js
ADDED
package/index.js
ADDED
package/load_services.js
ADDED
package/package.json
ADDED
package/post_request.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PROD } from "@env";
|
|
2
|
+
import get_service from "./get_service.js";
|
|
3
|
+
|
|
4
|
+
const post_request = async (url, body) => {
|
|
5
|
+
let response;
|
|
6
|
+
|
|
7
|
+
if (url.startsWith("$")) {
|
|
8
|
+
url = url.split("$");
|
|
9
|
+
url = [url[0], url.slice(1).join("$")];
|
|
10
|
+
|
|
11
|
+
let config = get_service(url[0]);
|
|
12
|
+
|
|
13
|
+
let domain = config.url || {};
|
|
14
|
+
|
|
15
|
+
domain = domain[PROD ? "prod" : "dev"];
|
|
16
|
+
|
|
17
|
+
if (!domain) {
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
message: "Missing Domain Name.",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
url = `${domain}/${url[1]}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
let ftch = await fetch(url, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
Accept: "application/json",
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify(body),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
response = await ftch.json();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.log(e);
|
|
39
|
+
response = {
|
|
40
|
+
ok: false,
|
|
41
|
+
message: e.message,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return response;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default post_request;
|