From 28608155bf1c19b3733a156a057e7f8c48dc3d4b Mon Sep 17 00:00:00 2001 From: Ivo Date: Thu, 7 Dec 2023 23:45:38 +0000 Subject: [PATCH] add Github Token to request when running on github codespaces --- convertPheno_client/src/code/axiosInstance.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 convertPheno_client/src/code/axiosInstance.js diff --git a/convertPheno_client/src/code/axiosInstance.js b/convertPheno_client/src/code/axiosInstance.js new file mode 100644 index 00000000..40ee32c1 --- /dev/null +++ b/convertPheno_client/src/code/axiosInstance.js @@ -0,0 +1,23 @@ +import axios from 'axios'; + +const axiosInstance = axios.create({ + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Connection': 'keep-alive', + } +}) + +axiosInstance.interceptors.request.use(config => { + if (window.location.hostname.endsWith('.github.dev') ) { + console.log('Running in Codespaces'); + config.headers['X-Github-Token'] = import.meta.env.VITE_GITHUB_TOKEN; + } + console.log('config', config); + return config; +}, error => { + console.log('error', error); + return Promise.reject(error); +}); + +export default axiosInstance; \ No newline at end of file