aboutsummaryrefslogtreecommitdiff
path: root/vnext/server/http.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-29 23:35:20 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commit47218df561e877265c739ffab59b760318ea3143 (patch)
tree166dd029133aca8d0d60af50535bb579bd6b8096 /vnext/server/http.js
parent3a403e4023ce3b7074a7922e7b504263ddc7a3d1 (diff)
Merge server routes from Next version
Diffstat (limited to 'vnext/server/http.js')
-rw-r--r--vnext/server/http.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/vnext/server/http.js b/vnext/server/http.js
new file mode 100644
index 00000000..74c51b0a
--- /dev/null
+++ b/vnext/server/http.js
@@ -0,0 +1,46 @@
+import axios from 'axios';
+var debug = require('debug')('http');
+
+
+/**
+ * @external Promise
+ * @see {@link http://api.jquery.com/Types/#Promise Promise}
+ */
+/**
+ * fetch message subscribers
+ *
+ * @param {URLSearchParams} params - request params
+ * @returns {Promise<import('../client').SecureUser[]>} subscribers list
+ */
+export function subscribers(params) {
+ return new Promise((resolve, reject) => {
+ client.get(`/notifications?${params.toString()}`)
+ .then(response => {
+ resolve(response.data);
+ })
+ .catch(reason => { reject(reason); });
+ });
+}
+
+/**
+ * delete invalid tokens
+ *
+ * @param {import('../client').Token[]} tokens tokens
+ */
+export const deleteSubscribers = async (tokens) => {
+ const response = await client.post('/notifications/delete', tokens);
+ return response.data;
+};
+
+const baseURL = process.env.JUICK_SERVICE_URL;
+const user = process.env.JUICK_SERVICE_USER;
+const password = process.env.JUICK_SERVICE_PASSWORD;
+
+/** @type { import('axios').AxiosInstance } */
+let client = axios.create({
+ baseURL: baseURL,
+ headers: user ? {
+ 'Authorization': 'Basic ' + Buffer.from(user + ':' + password).toString('base64')
+ } : {}
+});
+debug(`HTTP client initialized with base URL ${baseURL} ${ user? `and ${user} user` : ''}`);