1.1.2 • Published 5 years ago
@lukas3674/hbs-web-server v1.1.2
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!`);