go-oauth-example
go-oauth-example copied to clipboard
failed to fetch
Access to fetch at 'http://api.github.com/user' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
add https:
can fix it.
fetch('https://api.github.com/user', {
headers: {
// Include the token in the Authorization header
Authorization: 'token ' + token
}
})
// Parse the response as JSON
.then(res => res.json())
.then(res => {
console.log(res)
// Once we get the response (which has many fields)
// Documented here: https://developer.github.com/v3/users/#get-the-authenticated-user
// Write "Welcome <user name>" to the documents body
const nameNode = document.createTextNode(`欢迎登录, ${res.name}`)
document.body.appendChild(nameNode)
})
Agreed. I had the same error blocking the call to fetch() in welcome.html, but adding the protocol to HTTPS
fixes it (since many people don't use secure certificate on localhost).