我同时使用 npm 同时运行前端和后端,但仍然没有正确连接到后端。该路径生成正确并在邮递员中工作,但当我从站点调用它时却不行。我已经通过调试器运行它,并缩小了范围。我确信这与我设置代理的方式有关,但我不确定我到底是不是出错了帮助!
前端包.json
"proxy": "http://myIPaddress:4001",
"secure": false
redux 中的操作:
import {LOGIN} from './types'
const baseline = `http://myIPaddress/`
export const login = (username, password) => async dispatch => {
console.log('tell me the username', username.value, " and your password? ", password.value)
let path = `postLogin/`
let params = `${username.value}/${password.value}`
console.log('the path : ', `${baseline}${path}${params}`)
try{
// axios.default.header.get['Content-Type'] = ''
let res = await fetch(`${baseline}${path}${params}`,{
method: 'GET',
headers: {
'Content-type': 'application/json'
}
}
)
.then(res => res.json())
.then(
dispatch( {
type: LOGIN,
payload: res.json()
})
)
}
catch(e){
console.log(`can't find that user ${username.value}`)
}
}
如果有一个部分我没有包括你们都需要帮助我解决这个问题,请告诉我。
谢谢!