Wie man den Koa-HTTP-Antwortcode setzt

Um den HTTP-Antwortcode mit Koa zu setzen, verwenden Sie ctx.status = ...

koa_status.ts
ctx.status = 403;

Vollständiges Beispiel:

koa_example.js
const Koa = require("koa");

const app = new Koa();

app.use(async (ctx, next) => {
  ctx.status = 403;
  ctx.body = "Forbidden";
});

app.listen(3000);

Check out similar posts by category: JavaScript, NodeJS