README
content-handler-express
Emulate expressjs in your browser, using content-handler
Install
npm i content-handler-express
Usage
Create an app
Browser side
import ContentApplication from 'content-handler-express/content-application.js'
import html from 'content-handler-express/engines/html.js'
const document = window.document
const app = new ContentApplication()
export default app
.engine('html', html(app, document))
.set('origin', document.location.origin)
Server side
content-handler-express-node-engines
Add the express controller to your listeners
// ...
import express from 'content-handler-express/express.js'
ContentHandler
.getByDocument()
.addEventListener(anchor.selector, anchor.listen([
cache.default,
headers.xhr,
credentials.sameOrigin,
mode.sameOrigin,
redirect.follow,
referrer.client,
express(global)
]))
Listen a route
const template = '/home.html'
app.get(template, (request, response) => {
response.render(template, (error, html) => {
if (error) {
throw error
}
response.send(html)
})
})
Fill the HTML with some data
response.render(template, (error, html) => {
if (error) {
throw error
}
html.querySelector('main > h1').textContent = 'Hello world'
response.send(html)
})
For the rest, see the expressjs doc
https://expressjs.com/en/4x/api.html