Skip to content

Instantly share code, notes, and snippets.

@peerreynders
Created March 12, 2021 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peerreynders/cc0e343030837180f42036824883e1b6 to your computer and use it in GitHub Desktop.
Save peerreynders/cc0e343030837180f42036824883e1b6 to your computer and use it in GitHub Desktop.
Marko - first steps
// file: /src/index.js
import fastify from 'fastify';
import marko from 'marko';
import pointOfView from 'point-of-view';
const app = fastify({
logger: true
});
app.register(pointOfView, {
engine: {
marko
}
});
// Declare a route
app.get('/', getRoot);
// Run the server!
app.listen(3000, listenCb);
function getRoot(request, reply) {
reply.view('./pages/template.marko', { hello: 'world' });
}
function listenCb(err, address) {
if(err) {
app.log.error(err);
process.exit(1);
}
app.log.info(`server listening on ${address}`);
}
{
"name": "test",
"type": "module",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "cd ./src && node ./index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"fastify": "^3.14.0",
"marko": "^5.3.0",
"point-of-view": "^4.14.0"
}
}
<!DOCTYPE html>
<!-- file /src/pages/template.marko -->
<html>
<head>
<title>Hello ${input.hello}</title>
</head>
<body>
<h1>Hello ${input.hello}</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment