-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ab2e61
commit 358584c
Showing
13 changed files
with
513 additions
and
243 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,73 @@ | ||
import http from "http" | ||
|
||
// const server = http.createServer((req, res) => { | ||
// // Allow requests from any origin | ||
// res.setHeader("Access-Control-Allow-Origin", "*") | ||
|
||
// // Set other CORS headers as needed | ||
// res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE") | ||
// res.setHeader("Access-Control-Allow-Headers", "Content-Type") | ||
|
||
// // Respond with the data | ||
// res.writeHead(200, { "Content-Type": "application/octet-stream" }) | ||
|
||
// res.write("Hello World\n") | ||
|
||
// // Simulate streaming by sending chunks of data every 1 second | ||
// const intervalId = setInterval(() => { | ||
// res.write(`${new Date().toLocaleTimeString()}\n`) | ||
// }, 1000) | ||
|
||
// // End the stream and clear the interval after 5 seconds | ||
// setTimeout(() => { | ||
// clearInterval(intervalId) | ||
// res.end() | ||
// }, 5000) | ||
|
||
// // Clear the interval if the client disconnects before 5 seconds | ||
// res.on("close", () => clearInterval(intervalId)) | ||
// }) | ||
|
||
// server.listen(8080, () => { | ||
// console.log("Server is running on port 8080") | ||
// }) | ||
|
||
const server = http.createServer((req, res) => { | ||
// Allow requests from any origin | ||
res.setHeader("Access-Control-Allow-Origin", "*") | ||
|
||
// Set other CORS headers as needed | ||
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE") | ||
res.setHeader("Access-Control-Allow-Headers", "Content-Type") | ||
|
||
// Check if the client requested SSE | ||
if (req.headers.accept && req.headers.accept === "text/event-stream") { | ||
// Set headers for SSE | ||
res.writeHead(200, { | ||
"Content-Type": "text/event-stream", | ||
"Cache-Control": "no-cache", | ||
"Connection": "keep-alive", | ||
}) | ||
|
||
// Send an event every second | ||
const intervalId = setInterval(() => { | ||
res.write( | ||
`data: The server time is: ${new Date().toLocaleTimeString()}\n\n` | ||
) | ||
}, 1000) | ||
|
||
// Close the connection when the client disconnects | ||
req.on("close", () => { | ||
clearInterval(intervalId) | ||
res.end() | ||
}) | ||
} else { | ||
// Handle other requests (e.g., API requests, static files, etc.) | ||
res.writeHead(404) | ||
res.end() | ||
} | ||
}) | ||
|
||
server.listen(8080, () => { | ||
console.log("Server is running on port 8080") | ||
}) |
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,57 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Test send Function</title> | ||
</head> | ||
<body> | ||
<form id="myForm"> | ||
<input id="butt" type="text" name="title" value="My Title" /> | ||
<textarea name="body">This is the body of my post.</textarea> | ||
<button id="submitButton">Submit</button> | ||
</form> | ||
|
||
<script type="module"> | ||
import { $, $$ } from "../index.js" | ||
|
||
// submitButton.addEventListener("click", async () => { | ||
// const url = "https://jsonplaceholder.typicode.com/posts" // JSONPlaceholder API | ||
// const options = { | ||
// method: "POST", | ||
// json: true, | ||
// oncomplete: () => { | ||
// // Callback function to handle completion | ||
// console.log("Request completed.") | ||
// }, | ||
// onerror: (error) => { | ||
// // Callback function to handle errors | ||
// console.error("Request error:", error) | ||
// }, | ||
// } | ||
|
||
// try { | ||
// const response = await send(url, formElement, options) | ||
// console.log("Response:", response) | ||
// } catch (error) { | ||
// console.error("Error:", error) | ||
// } | ||
// }) | ||
|
||
$("#submitButton").on("click", async (event) => { | ||
$("#submitButton").send({ | ||
event, | ||
url: "https://jsonplaceholder.typicode.com/posts", | ||
json: true, | ||
oncomplete: (r) => { | ||
console.log("Response:", r) | ||
$("#submitButton").text(JSON.stringify(r)) | ||
}, | ||
onerror: (error) => { | ||
console.error("Request error:", error) | ||
}, | ||
}) | ||
}) | ||
</script> | ||
</body> | ||
</html> |
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
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,44 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>jQuery is for old people.</h1> | ||
<div class="card"> | ||
<button id="counter" type="button"></button> | ||
</div> | ||
<h2 class="truth">This will disappear.</h2> | ||
<h3 class="truth">I love you.</h3> | ||
</div> | ||
<input type="text" /> | ||
<div class="container" id="parentTwo"> | ||
<input id="myFavorite" type="text" /> | ||
<h4 class="truth">Why are you still reading this?</h4> | ||
</div> | ||
<script type="module"> | ||
import { $, $$ } from "../index.js" | ||
let count = 0 | ||
const counter = $("#counter").text(count) | ||
counter | ||
.text(count) | ||
.on("click", () => { | ||
count++ | ||
counter.text(count) | ||
}) | ||
.css("border", "2px solid black") | ||
.css({ | ||
padding: "10px", | ||
borderRadius: "5px", | ||
cursor: "pointer", | ||
}) | ||
.parent() | ||
.css("border", "2px solid red") | ||
.parent() | ||
.css("border", "2px solid blue") | ||
</script> | ||
</body> | ||
</html> |
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
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
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
Oops, something went wrong.