-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.ts
53 lines (42 loc) · 1.35 KB
/
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
51
52
53
/**
* Run this example using:
*
* deno run --allow-net --allow-read --unstable ./examples/eta/index.ts
*
* Note: you have to use --unstable because Eta uses the std 'fs' module (which requires --unstable)
*/
import { opine, serveStatic } from "../../mod.ts";
import { renderFile } from "https://deno.land/x/[email protected]/mod.ts";
import { dirname, join } from "../../deps.ts";
const app = opine();
const __dirname = dirname(import.meta.url);
// Register Eta as .html.
app.engine(".html", renderFile);
// Optional since opine defaults to CWD/views
app.set("views", join(__dirname, "views"));
// Path to our public directory
app.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");
// Disable caching (comment out in production)
app.set("view cache", false);
// Dummy users
const users = [
{ name: "Deno", email: "[email protected]" },
{ name: "SuperDeno", email: "[email protected]" },
{ name: "Deno the Dinosaur", email: "[email protected]" },
];
app.get("/", (req, res) => {
res.set("cache-control", "no-store").render("index", {
users,
title: "Eta example",
header: "Some users",
});
});
if (import.meta.main) {
app.listen(3000);
console.log("Opine started on port 3000");
}
export { app };