-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add a page for testing login CORS
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Login form</title> | ||
</head> | ||
|
||
<body> | ||
<form id="loginForm"> | ||
<input type="text" id="username" /><br /> | ||
<input type="password" id="password" /><br /> | ||
<button type="submit">Submit</button> | ||
<p id="result"></p> | ||
</form> | ||
</body> | ||
<script> | ||
window.onload = function () { | ||
document.getElementById('loginForm').onsubmit = function () { | ||
document.getElementById('result').innerHTML = '' | ||
const username = document.getElementById('username').value | ||
const password = document.getElementById('password').value | ||
const body = JSON.stringify({ username, password }) | ||
fetch('http://localhost:3000/signalk/v1/auth/login', { | ||
method: 'POST', | ||
withCredentials: true, | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body | ||
}) | ||
.then(r => r.json()) | ||
.then(r => { | ||
document.getElementById('result').innerHTML = JSON.stringify(r) | ||
}) | ||
return false; | ||
} | ||
} | ||
</script> | ||
|
||
</html> |