1.1.2 • Published 5 years ago

@lukas3674/hbs-web-server v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Simple JS Web-Server with HBS

Usage:

Folder-Structure

>your_project
    >hbs
        >layouts
            >layout.hbs
        >public
            >js
                script.js
            ...
        >views
            >view.hbs
    >index.js
    >...

index.js

const WS = require(`@lukas3674/hbs-web-server`);
const path = require(`path`);

const ws = new WS({
    port: 8888,
    cookieKey: `justSomeRandomKey`,
    hbsDir: path.join(__dirname, `hbs`),
}).start();

ws.get(`/`, (req, res) => {
    res.render(`view`, {
        title: `Test Website`,
        text: `My test website text ...`
    });
});

ws.get(`/stop`, (req, res) => {
    res.send(`stopped`);
    ws.stop();
});

layout.hbs

<!DOCTYPE html>
<html style="background-color: #000000">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="js/script.js"></script>

        {{#if title}}
            <title>{{title}}</title>
        {{/if}}
    </head>
    <body>
        {{{body}}}
    </body>
</html>

view.hbs

<div style="color: #ffffff">
    {{#if text}}
        <h1 style="text-align: center">{{text}}</h1>
    {{/if}}
</div>

script.js

console.log(`Hello Website!`);
1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago