mirror of
https://github.com/BradNut/node-auth
synced 2025-09-08 17:40:17 +00:00
Calling post of form data.
This commit is contained in:
parent
fb671e0b6f
commit
3b15223b1d
2 changed files with 36 additions and 0 deletions
|
|
@ -17,6 +17,10 @@ async function startApp() {
|
||||||
root: path.join(__dirname, "public"),
|
root: path.join(__dirname, "public"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post('/api/register', {}, (request, reply) => {
|
||||||
|
console.log('request', request.body.email, request.body.password);
|
||||||
|
})
|
||||||
|
|
||||||
// app.get("/", {}, (request, reply) => {
|
// app.get("/", {}, (request, reply) => {
|
||||||
// reply.send({
|
// reply.send({
|
||||||
// data: "hello world",
|
// data: "hello world",
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,37 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello</h1>
|
<h1>Hello</h1>
|
||||||
|
<h3>Register Form</h3>
|
||||||
|
<form id="register-form">
|
||||||
|
<input type="email" name="email">
|
||||||
|
<input type="password" name="password">
|
||||||
|
<button type="submit">Register</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
;(() => {
|
||||||
|
const form = document.getElementById("register-form")
|
||||||
|
|
||||||
|
form.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
const values = Object.values(form).reduce((obj, field) => {
|
||||||
|
if (field.name) {
|
||||||
|
obj[field.name] = field.value
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}, {})
|
||||||
|
const res = await fetch('/api/register', {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(values),
|
||||||
|
headers: { "Content-type": "application/json; charset=UTF-8"},
|
||||||
|
})
|
||||||
|
console.log("values", values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in a new issue