1.4.1 • Published 5 years ago

content-handler-express v1.4.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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

License

MIT

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago