Skip to content

feat: implement joke API with Express and add .gitignore#257

Merged
GregorBiswanger merged 1 commit into
mainfrom
feature/jokes-http-api
Jan 29, 2026
Merged

feat: implement joke API with Express and add .gitignore#257
GregorBiswanger merged 1 commit into
mainfrom
feature/jokes-http-api

Conversation

@GregorBiswanger
Copy link
Copy Markdown
Owner

closed #256

Copilot AI review requested due to automatic review settings January 29, 2026 08:30
@github-actions
Copy link
Copy Markdown
Contributor

Security Probleme

  1. .env-Dateien werden ignoriert

    • Gut: .env wird in .gitignore aufgenommen, um Umgebungsvariablen geheim zu halten.
    • Empfehlung: Die App nutzt bisher keine Konfigurationsvariablen (aus process.env), aber es sollten keine sensiblen Daten im Sourcecode landen. Falls Umgebungsvariablen wichtig werden, bitte dotenv-Paket nutzen und .env lokal halten.
  2. Keine Eingabevalidierung oder Rate Limiting

    • Die API /api/jokes ist öffentlich und liefert bei jedem Aufruf einen Witz. Da keine User-Input verarbeitet wird, besteht kein direktes Injection-Risiko.
    • Aber: Es gibt kein Rate Limiting. Theoretisch kann ein Angreifer die API mit Anfragen überfluten und damit die Verfügbarkeit beeinträchtigen (DoS).
    • Lösung: Middleware wie express-rate-limit einbauen, um die Anzahl der Requests pro IP zu begrenzen.
  3. Keine Sicherheits-HTTP-Header

    • Es werden keine Sicherheits-Header gesetzt (z. B. helmet).
    • Auch wenn die App nur eine simple API liefert, empfiehlt sich der Einsatz von helmet zur Reduzierung potentieller Risiken.
  4. Abhängigkeiten

    • express wird verwendet, am besten auf eventuelle Sicherheitsupdates achten, z.B. durch npm audit.

Performance Probleme

  1. Jokes im Speicher

    • Aktuell wird das Witze-Array bei jedem Start in den Speicher geladen. Bei nur 10 Witzen ist das unproblematisch. Bei größeren Datenmengen oder persistenter Witzesammlung sollte eine Datenbank oder Caching-Lösung geprüft werden.
  2. Unnötige Zufallsberechnung

    • Zufallsauswahl über Math.random() ist performant und für diesen Anwendungsfall passend.

Zusammenfassung & Empfehlungen

  • Security:
    • express-rate-limit installieren und nutzen, um Missbrauch vorzubeugen.
    • helmet für Sicherheits-Header hinzufügen.
    • Sensible Daten in .env halten, bei Bedarf dotenv nutzen.
  • Performance:
    • Für aktuellen Umfang keine Probleme.
    • Bei zukünftiger Skalierung Auslagerung der Witze in persistenten Speicher prüfen.

Beispiel für Verbesserungen in app.js

const helmet = require('helmet');
const rateLimit = require('express-rate-limit');

app.use(helmet());

const limiter = rateLimit({
  windowMs: 1 * 60 * 1000, // 1 min
  max: 20, // max 20 Anfragen pro IP in 1 min
});

app.use('/api/', limiter);

Ich gebe den PR frei.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a simple Express-based HTTP API that serves random jokes and adds basic project configuration for a Node.js app, addressing issue #256.

Changes:

  • Add package.json configuring the project as an Express-based Node.js service with a start script.
  • Implement app.js with an in-memory list of 10 jokes and a /api/jokes endpoint returning a random joke as JSON.
  • Add a .gitignore for common Node.js, environment, log, build, coverage, and IDE artifacts.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
package.json Defines the Node.js project metadata, main entry (app.js), and Express dependency to run the joke API.
app.js Creates an Express server exposing /api/jokes that returns a randomly selected joke from a static list of 10 jokes.
.gitignore Excludes Node modules, lock files, environment files, logs, build artifacts, coverage, and IDE-specific files from version control.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GregorBiswanger GregorBiswanger merged commit 4b1b4a4 into main Jan 29, 2026
7 checks passed
@GregorBiswanger GregorBiswanger deleted the feature/jokes-http-api branch January 29, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ein Joke Web-Service

2 participants