serve javascript from static
This commit is contained in:
parent
d7ef06b487
commit
e7342828c8
2 changed files with 39 additions and 37 deletions
38
src/public/javascript/index.js
Normal file
38
src/public/javascript/index.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
window.onload = function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
console.log("This code runs 2 seconds after the window has loaded.");
|
||||||
|
const npub = window.nostr.getPublicKey();
|
||||||
|
let pubkeyP = document.querySelector("#pubkey-p");
|
||||||
|
let pubkeySpan = document.querySelector("#pubkey-span");
|
||||||
|
|
||||||
|
npub.then(async function (npub) {
|
||||||
|
console.log(npub);
|
||||||
|
pubkeyP.style.display = "block";
|
||||||
|
pubkeySpan.innerText = npub;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/session-npubbed', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
"npub": npub
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
console.log('SessionNpubbed record created successfully:', data);
|
||||||
|
} else {
|
||||||
|
const error = await response.json();
|
||||||
|
console.error('Failed to create sessionNpubbed record:', error);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('An error occurred:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
<title>Hello World</title>
|
<title>Hello World</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<script src="/javascript/index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -21,44 +22,7 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
window.onload = function () {
|
|
||||||
setTimeout(function () {
|
|
||||||
console.log("This code runs 2 seconds after the window has loaded.");
|
|
||||||
const npub = window.nostr.getPublicKey();
|
|
||||||
let pubkeyP = document.querySelector("#pubkey-p");
|
|
||||||
let pubkeySpan = document.querySelector("#pubkey-span");
|
|
||||||
|
|
||||||
npub.then(async function (npub) {
|
|
||||||
console.log(npub);
|
|
||||||
pubkeyP.style.display = "block";
|
|
||||||
pubkeySpan.innerText = npub;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/session-npubbed', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
"npub": npub
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
console.log('SessionNpubbed record created successfully:', data);
|
|
||||||
} else {
|
|
||||||
const error = await response.json();
|
|
||||||
console.error('Failed to create sessionNpubbed record:', error);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('An error occurred:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
)
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue