From d6860663398761bb7f37aeff83404e28492eb65f Mon Sep 17 00:00:00 2001 From: HangerThem Date: Mon, 25 May 2026 17:10:08 +0200 Subject: [PATCH] Block 01, Week 01 added a bit of styling --- .../demo/public/style.css | 76 +++++++++++++++++++ .../demo/server.ts | 31 +++++--- 2 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 block-01/week-01-the_web_under_the_hood/demo/public/style.css diff --git a/block-01/week-01-the_web_under_the_hood/demo/public/style.css b/block-01/week-01-the_web_under_the_hood/demo/public/style.css new file mode 100644 index 0000000..1a37786 --- /dev/null +++ b/block-01/week-01-the_web_under_the_hood/demo/public/style.css @@ -0,0 +1,76 @@ +* { + font-family: "Courier New", Courier, monospace; + box-sizing: border-box; +} + +body { + background-color: #040b04; + color: #7cff7c; + text-shadow: 0 0 5px rgba(124, 255, 124, 0.35); + line-height: 1.5; + margin: 0; + padding: 24px; +} + +h1 { + color: #a8ff9f; + text-shadow: 0 0 8px rgba(124, 255, 124, 0.55); +} + +p { + color: #7cff7c; + font-size: 18px; +} + +a { + color: #9fffa0; + text-decoration: underline; +} + +a:hover { + color: #d6ffd6; +} + +ul { + list-style-type: square; + padding-left: 24px; +} + +::selection { + background: rgba(124, 255, 124, 0.25); + color: #ffffff; +} + +form { + margin-top: 16px; + max-width: 400px; +} + +label { + display: flex; + flex-direction: column; + margin-bottom: 12px; +} + +input { + padding: 8px; + border: 1px solid #7cff7c; + background-color: transparent; + color: #7cff7c; + font-size: 16px; + outline: none; +} + +button { + padding: 10px 16px; + background-color: #7cff7c; + color: #040b04; + border: none; + cursor: pointer; + font-size: 16px; + font-weight: bold; +} + +button:hover { + background-color: #9fffa0; +} diff --git a/block-01/week-01-the_web_under_the_hood/demo/server.ts b/block-01/week-01-the_web_under_the_hood/demo/server.ts index 63ee754..191a9d3 100644 --- a/block-01/week-01-the_web_under_the_hood/demo/server.ts +++ b/block-01/week-01-the_web_under_the_hood/demo/server.ts @@ -24,9 +24,13 @@ app.use((req, res, next) => { next() }) +// Serve static files from the "public" directory (for CSS, images, etc.) +app.use(express.static("public")) + // Simple GET: echoes request info back as HTML app.get("/", (req, res) => { res.send(` +

HTTP Echo Server

Check your terminal — the server printed everything it received.

Try these:

@@ -35,6 +39,8 @@ app.get("/", (req, res) => {
  • Set a cookie
  • Show cookies the server received
  • JSON response
  • +
  • Delayed response
  • +
  • HTTP status codes
  • `) }) @@ -42,10 +48,11 @@ app.get("/", (req, res) => { // Form page: allows to submit a POST and see the body app.get("/form", (req, res) => { res.send(` +

    Login Form

    -

    -

    + +

    Submit this and watch the terminal. Also check DevTools → Network tab.

    @@ -56,6 +63,7 @@ app.get("/form", (req, res) => { app.post("/login", (req, res) => { const { username, password } = req.body res.send(` +

    Server received your POST

    Username: ${username}

    Password: ${password}

    @@ -71,6 +79,7 @@ app.get("/set-cookie", (req, res) => { maxAge: 60 * 60 * 1000, // 1 hour }) res.send(` +

    Cookie Set

    The server sent a Set-Cookie header. Check DevTools → Network → Response Headers.

    Now visit show-cookies — the browser will automatically send it back.

    @@ -81,6 +90,7 @@ app.get("/set-cookie", (req, res) => { app.get("/show-cookies", (req, res) => { const cookieHeader = req.headers["cookie"] || "none" res.send(` +

    Cookies the server received

    Cookie: ${cookieHeader}

    The browser sent this automatically — you didn't write any JavaScript for that.

    @@ -100,15 +110,17 @@ app.get("/json", (req, res) => { // Delayed response: simulates a slow server app.get("/delay", (req, res) => { setTimeout(() => { - res.send( - "

    Delayed Response

    This response was delayed by 5 seconds.

    ", - ) + res.send(` + +

    Delayed Response

    This response was delayed by 5 seconds.

    + `) }, 5000) }) // Show all the different HTTP status codes app.get("/status", (req, res) => { res.send(` +

    HTTP Status Codes

    2xx Success