1 | # Hapi + Marko
|
2 |
|
3 | See the [marko-hapi](https://github.com/marko-js-samples/marko-hapi) sample
|
4 | project for a working example.
|
5 |
|
6 | ## Installation
|
7 |
|
8 | ```bash
|
9 | npm install hapi --save
|
10 | npm install marko --save
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```javascript
|
16 | "use strict";
|
17 |
|
18 | require("marko/node-require");
|
19 |
|
20 | const Hapi = require("hapi");
|
21 |
|
22 | const indexTemplate = require("./index");
|
23 |
|
24 | const server = new Hapi.Server();
|
25 | const port = 8080;
|
26 |
|
27 | server.connection({ port });
|
28 |
|
29 | server.route({
|
30 | method: "GET",
|
31 | path: "/",
|
32 | handler(request, reply) {
|
33 | return reply(
|
34 | indexTemplate.stream({
|
35 | name: "Frank",
|
36 | count: 30,
|
37 | colors: ["red", "green", "blue"]
|
38 | })
|
39 | ).type("text/html");
|
40 | }
|
41 | });
|
42 |
|
43 | server.start(err => {
|
44 | if (err) {
|
45 | throw err;
|
46 | }
|
47 |
|
48 | console.log(`Server running on port: ${port}`);
|
49 | });
|
50 | ```
|