Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

DOZ server-side rendering

NotificationsYou must be signed in to change notification settings

dozjs/doz-ssr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOZ server-side rendering

Installation

npm install doz-ssr

Example with Koa

server.js

constKoa=require('koa');constserve=require('koa-static');constbody=require('koa-body');constDozSSR=require('doz-ssr');constdozSSR=newDozSSR('./dist/index.html');newKoa().use(serve('./public',{index:false})).use(body()).use(asyncctx=>{const[content]=awaitdozSSR.render(ctx.url,{baseUrl:ctx.protocol+'://'+ctx.host});ctx.body=content;}).listen(3000);

bundle.js

IMPORTANT, since 2.0.0 it's necessary to callwindow.SSR.ready() inside your Doz app

newDoz({root:'#app',template(h){returnh`            <div></div>        `},onMount(){if(window.SSR)window.SSR.ready();}});

index.html

<!DOCTYPE html><htmllang="en"><head><title>MyApp</title></head><body><divid="app"></div><scriptid="bundle"src="/bundle.js"></script></body></html>

API

DozSSR

Kind: global class

new DozSSR(entryFile, [opt])

ParamTypeDefaultDescription
entryFilestring

File index.

[opt]object

Options.

[opt.bundleId]string"bundle"

Bundle id selector.

[opt.appRootId]string"app"

App id selector.

[opt.docTypeString]string"<!DOCTYPE html>"

Document type.

dozSSR.getBundlePath() ⇒string

Get bundle path from src attribute

Kind: instance method ofDozSSR

dozSSR.render(routePath, [opts]) ⇒Promise.<*>

Render app

Kind: instance method ofDozSSR

ParamTypeDefaultDescription
routePathstring

The route path.

[opts]object

Rendering options

[opts.reloadBundle]booleanfalse

If true, the bundle will be reload every render call. This operation is slow so useful only in develop mode.

[opts.baseUrl]string"http://localhost"

The base url. Really this param is very important, you must fill it with your real domain in production environment.

[opts.inject]string

This options is useful to inject code before app bundle execution.

[opts.headers]object

Accepts the headers of the request`,

[opts.cleanerScript]booleanfalse

Cleaner script before to the client rendering`,

[opts.replacements]object

This options is useful to replace any placeholder like this%MY_PLACEHOLDER%,in this case, the key will beMY_PLACEHOLDER and the value "YOUR STRING". The perfect scenario are for example the meta tags values.

PLUGIN

There is a plugin that adds a method and a directive:

importssrPluginfrom'doz-ssr/plugin'Doz.use(ssrPlugin);// If you call isSSR() method inside your app you can check if it is in server environmentDoz.component('my-component',function(h){returnh`        <div>is server?${this.isSSR()}</div>    `})// If you want exclude (not visible) a component or part of html you can use the directive `d-ssr-invisible`Doz.component('my-component',function(h){returnh`        <div>            hello my friend            <!-- on server side this will be not shown -->            <div d-ssr-invisible>wow!</div>        </div>    `})

Changelog

You can view the changeloghere

License

doz-ssr is open-sourced software licensed under theMIT license

Author

Fabio Ricali

About

DOZ server-side rendering

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp