You just need import the file from github (or gitee)
import { Denly } from "https://deno.land/x/denly@V0.24/mod.ts";
let app = new Denly({
hostname: "127.0.0.1",
port: 808,
options: {
debug: true,
},
});
app.route.get("/", () => {
return "Hello Denly!";
});
app.run();
It's easy to use, you don't need to download other file, just import the package from online.
if you want the server automatic restart after the file edited, then you can use hot-loading.
deno run --allow-run https://deno.land/x/denly@V0.24/debug.ts ./mod.ts
You can define a URL parameter based on a regular expression.
app.route.regex("letter", /^[a-zA-Z]+$/g);
app.route.get("/user/:letter",(name: string) => {
return `Hello ${name}`;
});
The framework is equipped with the following regular expressions by default:
You can send different error status codes and customize how you handle them.
app.route.fallback(404, () => {
return {
header: new Headers(), // A headers object
body: new TextEncoder().encode("<h1>404 Not Found</h1>"),
};
});
// trigger it
app.route.get("/error/404",() => {
return app.response.abort(404);
});
You can simply return a file.
app.route.get("/image",() => {
// Auto-updates headers based on the suffix.
return app.response.file("./background.jpg");
});
The file function have second parameter can set Content-Type.
app.route.resource("/static", "./public");
You can bind a static routes by passing the path to the local folder and the public alias to the resource function.
const file = app.request.file("file");
Deno.writeFileSync(_tempdir + "/runtime/upload/" + file.name, new Uint8Array(await file.arrayBuffer()));
You can use Request.file to upload file.
Author: ZhuoEr Liu mrxzx@qq.com
I am a back-end engineer and have recently been learning how to use Deno.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。