Created
January 8, 2021 13:16
-
-
Save neilhoff/6ea98b6c9c2ef2225b9545c11ca34f34 to your computer and use it in GitHub Desktop.
Architect when using CORS doesn't allow 'authorization' header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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