You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bun + stricjs应用:添加访问日志/中间件及代码未触发问题

Bun + stricjs 全局前置代码不执行的修复方案
  • 问题出在你的中间件没有传递请求控制权:当前的use回调只执行了日志输出,但没有让请求继续向下匹配后续的路由,导致请求到这里就直接终止了,自然不会触发/view/*的处理逻辑。
  • 只需在中间件里调用ctx.next()就能解决:
export default new Router({hostname: "0.0.0.0"})
  .use('GET', "/*", ctx => {
    console.log(`Applying super complex business rules`);
    // 调用next()让请求继续流转到下一个路由处理函数
    return ctx.next();
  })
  .get("/view/*", dir("./public"));
  • 如果要让前置代码对所有HTTP方法生效,把use的第一个参数改成"*"即可:
.use("*", "/*", ctx => {
  console.log(`Applying super complex business rules for all methods`);
  return ctx.next();
})

内容的提问来源于stack exchange,提问作者Henrique Capozzi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 18:05:00