Package Exports
- doz-ssr
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (doz-ssr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
doz-ssr
DOZ server-side rendering
Installation
npm install doz-ssr --saveExample with Koa
server.js
const Koa = require('koa');
const serve = require('koa-static');
const body = require('koa-body');
const DozSSR = require('doz-ssr');
const dozSSR = new DozSSR('./dist/index.html');
new Koa()
.use(serve('./public', {index: false}))
.use(body())
.use(async ctx => {
ctx.body = await dozSSR.render(ctx.path);
})
.listen(3000);index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>MyApp</title>
</head>
<body>
<div id="app"></div>
<script id="bundle" src="/bundle.js"></script>
</body>
</html>API
DozSSR
Kind: global class
- DozSSR
- new DozSSR(entryFile, [opt])
- .setContent(entryContent)
- .getContent() ⇒
string - .getBundleEl() ⇒
HTMLElement|null - .getBundlePath() ⇒
string - .render(routePath) ⇒
Promise.<any>
new DozSSR(entryFile, [opt])
| Param | Type | Default | Description |
|---|---|---|---|
| entryFile | string | file index |
|
| [opt] | object | options |
|
| [opt.bundleId] | string | "bundle" | bundle id selector |
| [opt.docTypeString] | string | "<!DOCTYPE html>" | document type |
| [opt.delayRender] | int | 0 | delay render in ms |
dozSSR.setContent(entryContent)
Set document content
Kind: instance method of DozSSR
| Param |
|---|
| entryContent |
dozSSR.getContent() ⇒ string
Get document content
Kind: instance method of DozSSR
dozSSR.getBundleEl() ⇒ HTMLElement | null
Get bundle HTMLElement
Kind: instance method of DozSSR
dozSSR.getBundlePath() ⇒ string
Get bundle path from src attribute
Kind: instance method of DozSSR
dozSSR.render(routePath) ⇒ Promise.<any>
Render app
Kind: instance method of DozSSR
| Param |
|---|
| routePath |
Changelog
You can view the changelog here
License
doz-ssr is open-sourced software licensed under the MIT license