`--::-`
.+ssssssys:
./++/- /ssssssssssyo -+oo/.
-yoshsso /ssssssssssssy/ /shh-sy.
`- .ysyo .sssosssssssosyy` osyy/.-
.oso+- .ssossysssohooyy` `ossy:
`ss. osssysosossosys +sss`
ss+. `-/sssssyyysssyy+:. `osss`
.osssssyyyyyssssosssyysssss+/+ssss-
./sssssssssssyssssyysssyyssss+:`
osssyyyysssyyssssyyysssys:.`
`` /ssyhhyhyssyyyssssyyhhhysy` .-.`
:++osoossyyo::...ossyyssssy+ .ohyss- .:ssyyy:
`: .:/:- `ossyyssssyo -shyyyss+/---:o
:/+//+sssys:`/sssss+++++/``` `
.osyyyssoo/. .:+ssyhyys+.
:/+osyyo. ./yyysoos-
` ` `-
A router that enables SSR (Server Side Rendering) for Meteor.
Basically, I create this package to learn more about Meteor and SSR.
But if this package can help someone, I would be delighted to help.
By default, Octopus adds support for
react
andreact-router v4
withReactRouterEngine
but you can create your own engine to render what you want on client and server. Also, you can use modules to add some good stuff like Redux or other.
Atmosphere:
$ meteor add c0r3y8:octopus
Some parts of Octopus API are not be able on both client and server so I try to provide a small example.
See ToDo example for more informations
Both:
// Some imports
const MainApp = () => (
<div>
<ul>
<li><Link to="/">{'Home'}</Link></li>
<li><Link to="/redux">{'Redux'}</Link></li>
</ul>
<Switch>
<Route exact path="/" component={AppContainer} />
<Route component={NotFound} />
</Switch>
</div>
);
const app = Octopus(MainApp);
Client:
// Do nothing
Server:
app.route({
exact: true,
path: '/'
}, function (req, res, next) {
// Do something
next();
});
JSDoc 3 is used in this package. In future, I'll deploy the generated doc for more API documentation.
Anywhere
Adds Octopus middleware in webapp
.
Returns Octopus instance.
Arguments
MainApp
(Function): This is your React app- [
clientConfig
] (Object): Custom client configuration- [
clientConfig.engine=new ReactRouterEngine
] (Object): use this option, if you want to use a custom engine - [
clientConfig.engineOptions={}
] (Object): use this option, if you want to pass custom options to the engine likerenderToString
- [
clientConfig.startup=true
] (Boolean): iftrue
, router starts automatically onMeteor.startup
but sometimes you need to start router when you want so you can set it tofalse
and callapp.render
manually.
- [
- [
serverConfig
] (Object): Custom server configuration- [
serverConfig.engine=new ReactRouterEngine
] (Object): use this option, if you want to use a custom engine - [
serverConfig.engineOptions={}
] (Object): use this option, if you want to pass custom options to the engine likerenderToString
orextras
body / headers
- [
Anywhere
Adds middleware callback.
Arguments
callback
(Function):- On Client: Callback is called (
callback()
) without arguments. It's just like a before render hook. - On Server: Callback is called (
callback(req, res, next)
) with request, response and next arguments. You can use this to do some checks or to pass custom context to other middleware or route callback by usingthis
, ex:this.store = createStore(...)
.
- On Client: Callback is called (
If you want to access to middleware context (
this
) in your callback, do not use arrow function.
Anywhere
Adds module.
Arguments
Module
(Function|Object): it can be an instance or a class (ES2015), if it's afunction
then callnew Module
else use Module directly- [
options={}
] (Object):- [
options.config
] (Object): if it's set andModule
is a function then passconfig
as an argument tonew Module(config)
- [
options.engineOptions=true
] (Boolean): iftrue
,Module
can set engine options - [
options.middlewares=true
] (Boolean): iftrue
,Module
can add middleware - [
options.routes=true
] (Boolean): Server only, iftrue
,Module
can add route
- [
Server
Adds route.
Arguments
routeConfig
(Object):- [
routeConfig.exact=false
] (Boolean): iftrue
, path must be matched exactly with request url routeConfig.path
(String): an Express-style path- [
routeConfig.strict=false
] (Boolean): iffalse
, the trailing slash is optional
- [
callback
(Function): callback is called if request url matches with a route path. For dynamic route ex:/user/:name
, you can access to url parameters withthis.params.name
.
If you want to access to route context (
this
) in your callback, do not use arrow function.
To do
To do
This package is based or have code from over package but not use them directly. How I said, basically I create this package for learn more about SSR with Meteor. So big thanks to: