Files
suwayomi-material-you-webui/src/util/client.tsx

30 lines
950 B
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
2021-03-07 16:27:13 +03:30
import axios from 'axios';
import storage from './localStorage';
const { hostname, port, protocol } = window.location;
2021-03-07 16:27:13 +03:30
// if port is 3000 it's probably running from webpack devlopment server
let inferredPort;
if (port === '3000') { inferredPort = '4567'; } else { inferredPort = port; }
const client = axios.create({
// baseURL must not have traling slash
baseURL: storage.getItem('serverBaseURL', `${protocol}//${hostname}:${inferredPort}`),
2021-03-07 16:27:13 +03:30
});
client.interceptors.request.use((config) => {
if (config.data instanceof FormData) {
Object.assign(config.headers, { 'Content-Type': 'multipart/form-data' });
}
return config;
});
2021-03-07 16:27:13 +03:30
export default client;