提交 7f5f3ac8 编写于 作者: D DebugIsFalse

fix: token

上级 a72bbaab
const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run'
const useFetchRequest = (baseUrl) => {
baseUrl = baseUrl || BASE_URL
const config = {
......@@ -7,6 +8,10 @@ const useFetchRequest = (baseUrl) => {
const fetchRequest = (url, fetchConfig) => {
url = `${baseUrl}${url}`
fetchConfig = fetchConfig || {}
fetchConfig.headers = fetchConfig.headers || {}
if (window.localStorage) {
fetchConfig.headers.Authorization = localStorage.getItem('token')
}
fetchConfig.method = (fetchConfig.method || 'get').toLocaleUpperCase()
fetchConfig = Object.assign(config, fetchConfig)
return new Promise((resolve, reject) => {
......
import { fetchEventSource } from '@microsoft/fetch-event-source'
const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run'
export default (url, { onmessage, onerror, controller, params }) => {
fetchConfig.headers = fetchConfig.headers || {}
console.log(window)
fetchEventSource(`${BASE_URL}${url}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': '*/*'
'Accept': '*/*',
'Authorization': window && window.localStorage && window.localStorage.getItem('token')
},
body: JSON.stringify(params),
onmessage,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册