An Simple web-framework for Deno and Friends.
MIT License
Bot releases are hidden (Show)
Published by herudi over 1 year ago
Deno.serve
requires --unstable
.deno.json
remove files
for fmt
and lint
.Published by herudi over 1 year ago
Deno.serve
Published by herudi over 1 year ago
New Feature
serve-static
support SPA (single page app). set spa
to true
via options.Published by herudi over 1 year ago
import { Jwt } from "https://deno.land/x/[email protected]/lib/jwt.ts";
@Controller("/admin")
class AdminController {
...
@Jwt("secret")
@Get("/home")
home(rev: RequestEvent) {
console.log("Payload =>", rev.auth);
return "Welcome Home";
}
...
}
// http://localhost:8000/admin/home
// Authorization = Bearer <token>
Published by herudi over 1 year ago
import jwt from "https://deno.land/x/[email protected]/lib/jwt.ts";
const JWT_SECRET = "myjwtsecret";
app.post("/login", validate(LoginSchema), (rev) => {
// example payload.
const payload = {
iat: Math.round(Date.now() / 1000),
// expires 1 hours
exp: Math.round(Date.now() / 1000 + (1 * 60 * 60)),
user: rev.body.username,
};
return { token: jwt.encode(payload, JWT_SECRET) };
});
app.get("/admin/home", jwt(JWT_SECRET), (rev) => {
return `Welcome ${rev.auth.user}`;
});
Published by herudi over 1 year ago
RequestEvent
and HttpResponse
.serveNode
for custom server.import { serveNode } from "nhttp-land";
serveNode(() => new Response("hello node"), { port: 8000 });
Published by herudi over 1 year ago
import nhttp from "https://deno.land/x/[email protected]/mod.ts";
import validate, { z } from "https://deno.land/x/[email protected]/lib/zod-validator.ts";
const User = z.object({
username: z.string(),
password: z.string(),
user_info: z.object({
name: z.string(),
address: z.string(),
}),
});
const app = nhttp();
// support all content-type (json, multipart, raw, urlencoded)
app.post("/", validate(User), (rev) => {
return rev.body.user_info;
});
app.listen(8000, (_err, info) => {
console.log(`Running on port ${info.port}`);
});
Published by herudi over 1 year ago
h
for jsxPublished by herudi over 1 year ago
Published by herudi over 1 year ago
Published by herudi over 1 year ago
serve-static only GET/HEAD
Published by herudi over 1 year ago
import nhttp from "https://deno.land/x/[email protected]/mod.ts";
// or still supported
import { nhttp } from "https://deno.land/x/[email protected]/mod.ts";
Published by herudi over 1 year ago
Published by herudi over 1 year ago
Simple jsx libs with Helmet
for SEO.
/** @jsx n */
/** @jsxFrag n.Fragment */
import { n, Helmet, renderToHtml, FC } from "https://deno.land/x/[email protected]/lib/jsx.ts";
import { nhttp } from "https://deno.land/x/[email protected]/mod.ts";
const Home: FC<{ title: string }> = (props) => {
return (
<>
<Helmet>
<title>{props.title}</title>
</Helmet>
<h1>Home Page</h1>
</>
);
};
const app = nhttp();
app.engine(renderToHtml);
app.get("/", () => <Home title="welcome jsx" />);
app.listen(8000, () => {
console.log("> Running on port 8000");
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>welcome jsx</title>
</head>
<body>
<h1>Home Page</h1>
</body>
</html>
app.post("/", bodyParser({ json: "5kb" }), ({ body }) => body);
Published by herudi over 1 year ago
Published by herudi over 1 year ago
New Features:
Response
and Request
Web API for Nodejs
with same performance with native node:http(s)
Published by herudi over 1 year ago
partly
Published by herudi over 1 year ago
Deno
, Bun
, Node
.import { serveStatic } from "nhttp-land/serve-static";
const app = nhttp();
app.use(serveStatic("dir"));
multipart.upload
now support Deno
, Bun
, Node
.import { multipart, nhttp } from "nhttp-land";
const app = nhttp();
const upload = multipart.upload({ name: "image" });
app.post("/upload", upload, (rev) => {
console.log(rev.file);
console.log(rev.body);
return "Success Upload";
})
Published by herudi over 1 year ago
New Features
Published by herudi over 1 year ago
schemas
to class-validator.