deno.land / x / opine@2.3.4 / examples / dejs / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/** * Run this example using: * * deno run --allow-net --allow-read ./examples/dejs/index.ts * * after cloning the repo locally. */
import { opine, serveStatic } from "../../mod.ts";import { renderFileToString } from "https://deno.land/x/dejs@0.10.2/mod.ts";import { dirname, join } from "../../deps.ts";
const app = opine();const __dirname = dirname(import.meta.url);
// Register ejs as .html.app.engine(".html", renderFileToString);
// Optional since opine defaults to CWD/viewsapp.set("views", join(__dirname, "views"));
// Path to our public directoryapp.use(serveStatic(join(__dirname, "public")));
// Without this you would need to// supply the extension to res.render()// ex: res.render('users.html').app.set("view engine", "html");
// Dummy usersconst users = [ { name: "Deno", email: "deno@denoland.com" }, { name: "SuperDeno", email: "superdeno@denoland.com" },];
app.get("/", (_req, res) => { res.set("cache-control", "no-store").render("users", { users, title: "EJS example", header: "Some users", });});
if (import.meta.main) { app.listen(3000); console.log("Opine started on port 3000");}
export { app };
opine

Version Info

Tagged at
2 years ago