Deno 运行 也不能正常工作 d运行

Deno run is not working properly also drun

在创建了一个 index.ts 并编写了一个简单的代码来监听端口 3000 并在主体上打印 hello world 之后,我也无法 运行 或从 deno 的 d运行模块.

import { Application, Router } from "https://deno.land/x/denotrain@v0.5.0/mod.ts";

const app = new Application();

const router = new Router();

// Middleware 
app.use((ctx) => {

  ctx.cookies["user.session"] = "qwertz";
  ctx.cookies["a"] = "123";
  ctx.cookies["b"] = "456";
  delete ctx.cookies["user.session"];
  return;
});

router.get("/", (ctx) => {

  return new Promise((resolve) => resolve("This is the admin interface!")); 
});
router.get("/edit", async (ctx) => {
  return "This is an edit mode!"; 
});

app.get("/", (ctx) => {

  return {"hello": "world"};
});

app.use("/admin", router);

app.get("/:id", (ctx) => {
  // Use url parameters
  return "Hello World with ID: " + ctx.req.params.id
});

  return ctx.req.body;
});

await app.run()

运行 您的服务器使用以下命令:

drun watch --entryPoint=./server.ts --runtimeOptions=--allow-net

无论如何,大多数用于观察变化的 Deno 工具仍然存在漏洞,我建议使用 nodemon,带有 --exec 标志

nodemon --exec deno run --allow-net server.ts

为方便起见,您可以将 nodemon.json 与以下内容一起使用:

{
  "execMap": {
    "js": "deno run --allow-net",
    "ts": "deno run --allow-net"
  },
  "ext": "js,json,ts"
}

现在只需使用:nodemon server.ts

您的代码片段似乎有误,最后一个

  return ctx.req.body;
});

如果您修复该问题并使用最新的 deno (v1.0.1) 和 drun(v1.1.0) 版本,它应该可以使用以下命令: drun --entryPoint=index.ts --runtimeOptions=--allow-net

开发环境:- Windows 10

问题似乎是地址 0.0.0.0 特定于 mac only.Windows 没有' t 使用 0.0.0.0 地址。

进入localhost:3000 / 127.0.0.1:3000后。我能够得到 output.I 认为也许 Windows 将 0.0.0.0 重定向到本地主机。无论如何它解决了我的问题!

我在 windows。我遇到了同样的问题。那么,

const app = new Application({hostname:"127.0.0.1"});

我在打字稿中创建了应用程序,并提供了如上所示的参数主机名。 运行 deno 是这样的:

deno run --allow-net=127.0.0.1 index.ts

成功了。