mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 20:06:00 +00:00
#91 authorization header in electron app
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import resolveApi from './resolveApi';
|
||||
import resolveApi, { resolveApiHeaders } from './resolveApi';
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: resolveApi(),
|
||||
@@ -9,6 +9,7 @@ axiosInstance.defaults.headers = {
|
||||
'Cache-Control': 'no-cache',
|
||||
Pragma: 'no-cache',
|
||||
Expires: '0',
|
||||
...resolveApiHeaders(),
|
||||
};
|
||||
|
||||
export default axiosInstance;
|
||||
|
||||
@@ -20,3 +20,16 @@ export default function resolveApi() {
|
||||
}
|
||||
return window.location.origin;
|
||||
}
|
||||
|
||||
export function resolveApiHeaders() {
|
||||
if (window['require']) {
|
||||
const electron = window['require']('electron');
|
||||
|
||||
if (electron) {
|
||||
return {
|
||||
Authorization: electron.remote.getGlobal('authorization'),
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user