Frontly.js is express middleware that allows you to inject dynamic content into your webpages.
First, install frontly.
npm install frontly
Second, require it and use it as middleware.
const express = require('express');
const Frontly = require('frontly');
const app = express();
app.use(Frontly.middleware);
Third, make a HTML file that you want to serve.
<!DOCTYPE html>
<html>
<head>
<title>Frontly Demo</title>
</head>
<body>
<h1><::Frontly.Custom.Title::></h1> <!-- This is the syntax for Frontly in an HTML document. -->
</body>
</html>
Finally, serve the file with res.sendFileFrontly()
.
app.get('/', (req, res) => {
res.sendFileFrontly(__dirname + '/index.html', {
params: {
Title: "Hello, world!"
}
});
});
Here's the final product:
To escape normal HTML and use dynamic Frontly content, open it up with <::
and close with ::>
, putting whatever Frontly reference you would like in between. For example, you could do: <::Frontly.Version::>
, which uses the built in Frontly.Version
reference. To use a custom reference, use Frontly.Custom.*
.
-
- Use as express middleware
-
file
: The text you want to sendoptions
: Options for sending the fileoptions.params
: The custom Frontly parameters to pass- Similar to
req.send()
, but you can pass Frontly parameters
-
file
: The file you want to sendoptions
: Options for sending the fileoptions.params
: The custom Frontly parameters to pass- Similar to
req.sendFile()
, but you can pass Frontly parameters