Node.js 如何在特定的路由中指定膝关节炎中的静态文件夹?

Node.js 如何在特定的路由中指定膝关节炎中的静态文件夹?,node.js,koa,Node.js,Koa,我注意到Koa的中间件(如Koa static())在使用特定路由(如“dashboard”)时不支持为静态文件夹提供服务,它似乎只支持为静态文件夹提供全局服务……解决此问题的最佳解决方案是什么 例如,我可以尝试: app.use(...) .use(async function(ctx){ if ('/dashboard' === ctx.path) { let body = await static('./build'); return bo

我注意到Koa的中间件(如Koa static())在使用特定路由(如“dashboard”)时不支持为静态文件夹提供服务,它似乎只支持为静态文件夹提供全局服务……解决此问题的最佳解决方案是什么

例如,我可以尝试:

app.use(...)
   .use(async function(ctx){
      if ('/dashboard' === ctx.path) {
        let body = await static('./build');
        return body;
      }
   });

结果只是“未找到”。

使用koa安装:

npm i koa-mount

const mount = require('koa-mount');

...
.use(mount('/dashboard', static('./build')));
npm i koa-mount

const mount = require('koa-mount');

...
.use(mount('/dashboard', static('./build')));