javascript
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| javascript [2022-06-25 17:22:16] – [AJAX/AJAJ (fetch)] david | javascript [2026-05-16 12:12:24] (aktuell) – [video screenshot] david | ||
|---|---|---|---|
| Zeile 82: | Zeile 82: | ||
| ===== Beispielprogramme ===== | ===== Beispielprogramme ===== | ||
| + | |||
| + | |||
| + | ==== backend ==== | ||
| + | |||
| + | |||
| + | === test api === | ||
| + | |||
| + | API zum testen: Alle Anfragen werden geloggt und mit "Hello World!" | ||
| + | |||
| + | <code javascript test.js> | ||
| + | "use strict"; | ||
| + | |||
| + | import express from " | ||
| + | |||
| + | const app = express(); | ||
| + | const port = process.env.PORT || 3000; | ||
| + | |||
| + | app.use(express.json()); | ||
| + | app.use((req, | ||
| + | const payload = { | ||
| + | body: req.body ?? null, | ||
| + | headers: req.headers ?? null, | ||
| + | url: req.url ?? null, | ||
| + | }; | ||
| + | console.log(payload); | ||
| + | res.status(418); | ||
| + | res.send(" | ||
| + | next(); | ||
| + | }); | ||
| + | |||
| + | app.listen(port); | ||
| + | console.info(`Express started on port ${port}`); | ||
| + | |||
| + | </ | ||
| + | |||
| + | <code json package.json> | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | === hello world webserver (deno) === | ||
| + | |||
| + | <code javascript hello-world.ts> | ||
| + | import { serve } from " | ||
| + | |||
| + | const port = 80; | ||
| + | |||
| + | const handler = (): Response => { | ||
| + | return new Response(" | ||
| + | }; | ||
| + | |||
| + | serve(handler, | ||
| + | console.log(`Listening on http:// | ||
| + | |||
| + | </ | ||
| ==== frontend ==== | ==== frontend ==== | ||
| + | |||
| + | |||
| + | === video screenshot === | ||
| + | |||
| + | screenshot des ersten videos auf der aktuellen webseite | ||
| + | |||
| + | <code javascript> | ||
| + | (() => { | ||
| + | const format = { ext: " | ||
| + | const video = document.querySelector(" | ||
| + | const width = video.videoWidth; | ||
| + | const height = video.videoHeight; | ||
| + | const canvas = document.createElement(" | ||
| + | canvas.width = width; | ||
| + | canvas.height = height; | ||
| + | const ctx = canvas.getContext(" | ||
| + | ctx.drawImage(video, | ||
| + | const timestamp = (new Date()).toISOString() | ||
| + | .replaceAll(/ | ||
| + | .replaceAll(/ | ||
| + | canvas.toBlob((it) => { | ||
| + | const url = URL.createObjectURL(it); | ||
| + | const a = document.createElement(" | ||
| + | a.href = url; | ||
| + | a.download = `screenshot-${timestamp}.${format.ext}`; | ||
| + | a.click(); | ||
| + | URL.revokeObjectURL(url); | ||
| + | }, format.mime, | ||
| + | })(); | ||
| + | </ | ||
| Zeile 167: | Zeile 262: | ||
| } | } | ||
| }); | }); | ||
| - | |||
| - | </ | ||
| - | |||
| - | |||
| - | ==== backend ==== | ||
| - | |||
| - | |||
| - | === hello world webserver (deno) === | ||
| - | |||
| - | <code javascript hello-world.ts> | ||
| - | import { serve } from " | ||
| - | |||
| - | const port = 80; | ||
| - | |||
| - | const handler = (): Response => { | ||
| - | return new Response(" | ||
| - | }; | ||
| - | |||
| - | serve(handler, | ||
| - | console.log(`Listening on http:// | ||
| </ | </ | ||
/home/http/wiki/data/attic/javascript.1656177736.txt · Zuletzt geändert: von david
