sugo-endpoint-html
Sugo endpoint to server dynamic HTML
Last updated 6 months ago by realglobe .
Apache-2.0 · Repository · Bugs · Original npm · Tarball
$ cnpm install sugo-endpoint-html 
SYNC missed versions from official npm registry.

sugo-endpoint-html

Build Status npm Version JS Standard

Sugo endpoint to server dynamic HTML

Requirements

Node.js NPM

Installation

$ npm install sugo-endpoint-html --save

Usage

Create an instance and apply to sg-server (or sugo-cloud)

/** This is an example to use sugo-endpoint-html */

'use strict'

const sgServer = require('sg-server')

const sugoEndpointHTML = require('sugo-endoint-html')

const renders = {
  account: {
    profile: () => {
      // Returns html string to render
      return '<!DOCTYPE html><html><!- ... -></html>'
    },
    purchaseHistory: () => {
      return '<!DOCTYPE html><html><!- ... -></html>'
    }
  }
}

const server = sgServer({
  middlewares: [
    /* ... */
  ],
  endpoints: {
    // Exports actor module functions as http endpoint (like "/account/purchase-history")
    '/:module/:method': { GET: sugoEndpointHTML(renders) }
  }
})

server.listen(3000)


Then call the api from agent script.

/** This is example of client */

'use strict'

const arequest = require('arequest')

async function tryExampleClient () {
  let request = arequest.create()
  let { body, statusCode } = yield request({
    method: 'GET',
    // Specify the module and method as url with hyphen-case name
    url: `http://localhost/account/profile`,
  })
  // Return values as response body
  console.log(body) // -> <!DOCTYPE html><html><!-- ... --></html>
}

tryExampleClient().catch((err) => console.error(err))

Signature

sugoEndpointHtml(renderers, options) -> function

Sugo endpoint to server dynamic HTML

Args
Name Type Default Description
renderers Object<string, Object<string, function>> Renderer functions
options object Optional settings.

License

This software is released under the Apache-2.0 License.

Links

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |