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.url, false, ctx.protocol + '://' + ctx.host);
})
.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])
- .getBundlePath() ⇒
string - .render(routePath, [reloadBundle], [baseUrl]) ⇒
Promise.<*>
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.getBundlePath() ⇒ string
Get bundle path from src attribute
Kind: instance method of DozSSR
dozSSR.render(routePath, [reloadBundle], [baseUrl]) ⇒ Promise.<*>
Render app
Kind: instance method of DozSSR
| Param | Default | Description |
|---|---|---|
| routePath | The route path. |
|
| [reloadBundle] | false | If true, the bundle will be reload every render call. This operation is slow so useful only in develop mode. |
| [baseUrl] | http://localhost | The base url. Really this param is very important, you must fill it with your real domain in production environment. |
PLUGIN
Check if environment is server side from your app
import isSSR from 'doz-ssr/plugin'
Doz.use(isSSR);
// You now can call isSSR() method inside your app
Doz.component('my-component', function(h){
return h`<div>is server? ${this.isSSR()}</div>`
})Changelog
You can view the changelog here
License
doz-ssr is open-sourced software licensed under the MIT license