Allow proxy config for message

pull/940/head
tanasegabriel 2025-05-24 23:00:21 +01:00
parent c230392da8
commit f0f7e95c63
3 changed files with 47 additions and 31 deletions

View File

@ -15,10 +15,14 @@
</template> </template>
<script> <script>
import fetchOptions from "@/mixins/fetchOptions.js";
export default { export default {
name: "Message", name: "Message",
mixins: [fetchOptions],
props: { props: {
item: Object, item: Object,
proxy: Object,
}, },
data: function () { data: function () {
return { return {
@ -67,14 +71,15 @@ export default {
}, },
downloadMessage: function (url) { downloadMessage: function (url) {
return fetch(url, { headers: { Accept: "application/json" } }).then( const defaultHeaders = this.item?.headers || { Accept: "application/json" };
function (response) { const options = this.buildFetchOptions(defaultHeaders);
if (response.status != 200) {
return fetch(url, options).then((response) => {
if (response.status !== 200) {
return; return;
} }
return response.json(); return response.json();
}, });
);
}, },
mapRemoteMessage: function (message) { mapRemoteMessage: function (message) {

View File

@ -0,0 +1,29 @@
export default {
props: {
proxy: Object,
},
methods: {
buildFetchOptions(init = {}, options = {}) {
if (this.proxy?.useCredentials) {
options.credentials = "include";
}
if (this.proxy?.headers && !!this.proxy.headers) {
options.headers = this.proxy.headers;
}
// Each item can override the credential settings
if (this.item.useCredentials !== undefined) {
options.credentials =
this.item.useCredentials === true ? "include" : "omit";
}
// Each item can have their own headers
if (this.item?.headers && !!this.item.headers) {
options.headers = this.item.headers;
}
return Object.assign(options, init);
},
},
};

View File

@ -1,4 +1,7 @@
import fetchOptions from "@/mixins/fetchOptions.js";
export default { export default {
mixins: [fetchOptions],
props: { props: {
proxy: Object, proxy: Object,
}, },
@ -13,29 +16,6 @@ export default {
}, },
methods: { methods: {
fetch: function (path, init, json = true) { fetch: function (path, init, json = true) {
let options = {};
if (this.proxy?.useCredentials) {
options.credentials = "include";
}
if (this.proxy?.headers && !!this.proxy.headers) {
options.headers = this.proxy.headers;
}
// Each item can override the credential settings
if (this.item.useCredentials !== undefined) {
options.credentials =
this.item.useCredentials === true ? "include" : "omit";
}
// Each item can have their own headers
if (this.item.headers !== undefined && !!this.item.headers) {
options.headers = this.item.headers;
}
options = Object.assign(options, init);
if (path.startsWith("/")) { if (path.startsWith("/")) {
path = path.slice(1); path = path.slice(1);
} }
@ -46,6 +26,8 @@ export default {
url = `${this.endpoint}/${path}`; url = `${this.endpoint}/${path}`;
} }
const options = this.buildFetchOptions(init);
return fetch(url, options).then((response) => { return fetch(url, options).then((response) => {
let success = response.ok; let success = response.ok;
if (Array.isArray(this.item.successCodes)) { if (Array.isArray(this.item.successCodes)) {