Lobenton
Middlewares for isomorphic web with react and redux and express
Installing
$ npm install lobenton --save
Usage for your react redux project
- create folder "server" on root
- add entry file and follow:
var express = ;var lobenton = ; var instance = lobenton; var app = instance; var server = instance; moduleexport=server;
Class
BaseController
type
- class; extend by your controller
method
getRequest
- return express reqgetResponse
- return express resgetController
- return this controller namegetAction
- return this action namegetHeaderMap
- return express req.headerssetCookieMap
- return express req.cookiesgetParamMap
- return params that merge by {...req.params, ...req.query, ...req.body}render
html
- string; output str with res.sendpassToLayoutState
- Object; This object will passing to layout component you setting on config
json
state
- Object; output str with res.json
beforeAction
- run before corrent actionafterAction
- run after corrent actionbeforeRender
- run before corrent action renderafterRender
- run after corrent actions render
Middlewares
createRouter
type
- function; return express.router
params
config
- Object; format as follow:
"/path1" : "/path1-1" : method: 'get' layout: "/path/to/layout" "/path1-2" : method: "all" controller: "/path/to/FooController" action: "actionBar" method: "post" handler: actionLogin "/path2" : method: 'get' login: true "/path3(\d+)" : method: 'get' layout: "/path/to/layout" login: true
DeviceDetector
type
- function;
params
_defaultDevice
- string; input as follow:
const DESKTOP = "desktop";const MOBILE = "mobile";const TABLET = "tablet";
I18nDetector
type
- function;
params
_defaultDevice
- string; input as follow:
const EN = "en";const ZHTW = "zhTW";
requirePath
- string; locate of i18n template;
Log4jsMiddleware
type
- function;
params
config
- Object; format as follow:
"enabled" : true "replaceConsole" : true "showConsole" : true "format" : ":method :url" "filepath" : "/opt/node/logs" "rules" : "error" : "maxLogSize" : 20480 "backups" : 10 "filename": "/opt/node/logs/app.error.log" "warning" : "maxLogSize" : 20480 "backups" : 10 "filename": "/opt/node/logs/app.warning.log" "normal" : "maxLogSize" : 20480 "backups" : 10 "filename": "/opt/node/logs/app.access.log"
reactRouterRender
type
- function;
params
remoteDataUrl
- string; URL for send request to get data from serverreactRoutes
- Object; your react routerconfigureStore
- function; your storereducers
- function; your reducermiddlewares
- Array; your redux middlewares
RemoteFetchMiddleware
type
- function; In client, something, data server and main server ware different port. and this is access with cross domain. if you don't want to setting access control on your dev data server. you can using it, to remote fatch data from data server.
params
testWord
- Object; what the word in url you want to remote fatchremoteDataUrl
- string; URL for send request to get data from serverheaders
- Object; the header for request of remote fatchcallback
- Object; customized return value when get reqponse
asyncPreLoad
type
- function; Something, the react component for leading is very huge. You can using this to pre load file
params
preLoadArray
- Array; pre load file path or folder path