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

fix: token

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