go-oauth-example icon indicating copy to clipboard operation
go-oauth-example copied to clipboard

failed to fetch

Open pioneerlfn opened this issue 4 years ago • 2 comments

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.

pioneerlfn avatar Mar 12 '20 15:03 pioneerlfn

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)
		})

aturX avatar Oct 27 '20 09:10 aturX

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).

jasonsalas avatar Oct 31 '20 08:10 jasonsalas