该系统找不到指定的文件。 Deno 中的(os 错误 2)

The system cannot find the file specified. (os error 2) in Deno

使用视图引擎模板在 Deno 中渲染 HTML、CSS 和静态文件
我的代码:
文件夹结构

-public
  -css
     -main.css
  -js
     -app.js
-views
  -index.ejs
-server.ts


server.ts

/*  Introduction To Rendering HTML,CSS and Static Files inside Deno with View Engine Template */

// Importing Required Files And Packages Here.
import { Application, Router, send } from "https://deno.land/x/oak/mod.ts";
import {
  viewEngine,
  engineFactory,
  adapterFactory,
} from "https://deno.land/x/view_engine/mod.ts";

// Initializing App Here.
const app = new Application();

//  Setting Up Ejs Templating Engine Here.
const ejsEngine = engineFactory.getEjsEngine();
const oakAdapter = adapterFactory.getOakAdapter();

// Serving A Static Folder Here.
app.use(async (ctx,next)=>{
    await send(ctx,ctx.request.url.pathname,{
        root :`${Deno.cwd()}/public`
    })
    next();
})

// Initializing Router Here.
const router = new Router();

// Defining Routes Here.
router.get("/test", (ctx) => {
  ctx.render("views/index.ejs", {
    payload: {
      text: "test",
    },
  });
}).get("/", (ctx) => {
    ctx.render("views/index.ejs", {
      payload: {
        text: "<h1>Introduction To Templating Engines In Deno. </h1>",
      },
    });
  });



// MiddleWares Here.
app.use(viewEngine(oakAdapter, ejsEngine));
app.use(router.routes());
app.use(router.allowedMethods());

console.log("Server Started On Port Number 8000.");
await app.listen({ port: 8000 });

// Run : deno run --allow-net --allow-read server.ts

views/index.ejs :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Templating Engines</title>
    <link rel="stylesheet" href="/css/main.css" />
    <script src="/js/app.js" defer></script>
  </head>
  <body>
    <h1>Welcome To Deno World!</h1>
    <div><%- payload.text %></div>
    <p id="content"></p>
  </body>
</html>

public/css/main.css

p{
    color:red;
}

public/js/app.js

const content = document.getElementById("content");

const getDataJsFile = () => {
  content.innerHTML = `
    Java script Dummy Text  ::::::==>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Nesciunt quaerat
    perferendis consectetur doloribus repellendus ullam corrupti explicabo
    placeat reprehenderit ad.`;
};

getDataJsFile();

当我 运行 这段代码 deno 运行 --allow-net --allow-read server.tshttp://localhost:8000/ is working fine but in http://localhost:8000/test,我收到此错误:

The system cannot find the file specified. (os error 2) in Deno

所有对 /test 路由的 GET 请求都被静态内容中间件拦截,将该中间件功能移到通用中间件设置之后

app.use(viewEngine(oakAdapter, ejsEngine));
app.use(router.routes());
app.use(router.allowedMethods());

// Serving A Static Folder Here.
app.use(async (ctx,next)=>{
  await send(ctx,ctx.request.url.pathname,{
      root :`${Deno.cwd()}/public`
  })
  next();
})