mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-19 00:43:35 -05:00
Fix API proxy client request content type
This commit is contained in:
parent
3cd774b299
commit
3657da89b6
|
|
@ -21,19 +21,25 @@ export default class ZncProxyApi extends AbstractCoralApi implements CoralApiInt
|
|||
super();
|
||||
}
|
||||
|
||||
async fetchProxyApi<T = unknown>(url: URL | string, method = 'GET', body?: string, headers?: object) {
|
||||
async fetchProxyApi<T = unknown>(url: URL | string, method = 'GET', body?: string, _headers?: HeadersInit) {
|
||||
if (typeof url === 'string' && url.startsWith('/')) url = url.substring(1);
|
||||
|
||||
const base_url = typeof this.url === 'string' ? new URL(this.url) : this.url;
|
||||
if (typeof this.url === 'string' && !base_url.pathname.endsWith('/')) base_url.pathname += '/';
|
||||
|
||||
const headers = new Headers(_headers);
|
||||
|
||||
headers.append('Authorization', 'na ' + this.token);
|
||||
headers.append('User-Agent', getUserAgent(this.useragent));
|
||||
|
||||
if (body && !headers.has('Content-Type')) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
const [signal, cancel] = timeoutSignal();
|
||||
const response = await fetch(new URL(url, base_url), {
|
||||
method,
|
||||
headers: Object.assign({
|
||||
'Authorization': 'na ' + this.token,
|
||||
'User-Agent': getUserAgent(this.useragent),
|
||||
}, headers),
|
||||
headers,
|
||||
body,
|
||||
signal,
|
||||
}).finally(cancel);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user