mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
migrate to axios, front-end part of configurable ServerAddress
This commit is contained in:
@@ -1,10 +1,26 @@
|
||||
import axios from 'axios';
|
||||
import storage from './storage';
|
||||
/* 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/. */
|
||||
|
||||
const clientMaker = () => axios.create({
|
||||
baseURL: storage.getItem('baseURL', 'http://127.0.0.1:4567'),
|
||||
import axios from 'axios';
|
||||
import storage from './localStorage';
|
||||
|
||||
const { hostname, port, protocol } = window.location;
|
||||
|
||||
// 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}`),
|
||||
});
|
||||
|
||||
const client = clientMaker();
|
||||
client.interceptors.request.use((config) => {
|
||||
if (config.data instanceof FormData) {
|
||||
Object.assign(config.headers, { 'Content-Type': 'multipart/form-data' });
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export default client;
|
||||
|
||||
Reference in New Issue
Block a user