如何设置 Koa HTTP 响应代码
要使用 Koa 设置 HTTP 响应代码,使用 ctx.status = ...
koa_status.ts
ctx.status = 403;完整示例:
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
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow