mirror of https://github.com/bastienwirtz/homer
Allow proxy config for message
parent
c230392da8
commit
f0f7e95c63
|
@ -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;
|
return fetch(url, options).then((response) => {
|
||||||
}
|
if (response.status !== 200) {
|
||||||
return response.json();
|
return;
|
||||||
},
|
}
|
||||||
);
|
return response.json();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
mapRemoteMessage: function (message) {
|
mapRemoteMessage: function (message) {
|
||||||
|
|
|
@ -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);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
|
@ -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)) {
|
||||||
|
|
Loading…
Reference in New Issue