Created
March 12, 2021 03:29
-
-
Save peerreynders/cc0e343030837180f42036824883e1b6 to your computer and use it in GitHub Desktop.
Marko - first steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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}`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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