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 [2023-01-18 15:43:23] (aktuell) – [test api] 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:// | ||
| + | |||
| + | </ | ||
| Zeile 167: | Zeile 232: | ||
| } | } | ||
| }); | }); | ||
| - | |||
| - | </ | ||
| - | |||
| - | |||
| - | ==== 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
