Skip to content

Instantly share code, notes, and snippets.

@neilhoff
Created January 8, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilhoff/6ea98b6c9c2ef2225b9545c11ca34f34 to your computer and use it in GitHub Desktop.
Save neilhoff/6ea98b6c9c2ef2225b9545c11ca34f34 to your computer and use it in GitHub Desktop.
Architect when using CORS doesn't allow 'authorization' header
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
async function get () {
console.log('content-type header - loading.....')
try {
console.log('content-type header - Get')
const response = await axios.get('http://localhost:3333', {
headers: {
'content-type': 'application/x-www-form-urlencoded'
}
})
console.log('content-type header - Success!')
console.log(response)
} finally {
console.log('content-type header - Complete')
}
}
async function getAuthHeader () {
console.log('Authorization header - loading.....')
try {
console.log('Authorization header - Get')
const response = await axios.get('http://localhost:3333', {
headers: {
'Authorization': 'Bearer token'
}
})
console.log('Authorization header - Success!')
console.log(response)
} finally {
console.log('Authorization header - Complete')
}
}
async function init () {
await get()
console.log('============')
await getAuthHeader()
}
init()
</script>
Press F12 and Look at the console for results
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment