This package has been deprecated

Author message:

this package has been deprecated

lobenton

1.1.1 • Public • Published

Lobenton

Middlewares for isomorphic web with react and redux and express

Installing

$ npm install lobenton --save

Usage for your react redux project

  1. create folder "server" on root
  2. add entry file and follow:
var express = require('express');
var lobenton = require('lobenton');
 
var instance = lobenton.instance({
    name: "appName",
    config: config, // keep first, I have no idea this config I can do something for u
    expressInstance: express()
});
 
var app = instance.init(function(){
    this.express.use(/* something middleware */);
});
 
var server = instance.createServer(8080, function(){
    this.server.on('error', function onError(error){
        // do something
    });
    
    this.server.on('listening', function onListening(){
        console.log("Server startup");
    });
});
 
module.export=server;

Class

BaseController

  • type - class; extend by your controller

method

  • getRequest - return express req
  • getResponse - return express res
  • getController - return this controller name
  • getAction - return this action name
  • getHeaderMap - return express req.headers
  • setCookieMap - return express req.cookies
  • getParamMap - return params that merge by {...req.params, ...req.query, ...req.body}
  • render
    • html - string; output str with res.send
    • passToLayoutState - Object; This object will passing to layout component you setting on config
  • json
    • state - Object; output str with res.json
  • beforeAction - run before corrent action
  • afterAction - run after corrent action
  • beforeRender - run before corrent action render
  • afterRender - 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:
export const DESKTOP = "desktop";
export const MOBILE = "mobile";
export const TABLET = "tablet";

I18nDetector

  • type - function;

params

  • _defaultDevice - string; input as follow:
export const EN = "en";
export 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 server
  • reactRoutes - Object; your react router
  • configureStore - function; your store
  • reducers - function; your reducer
  • middlewares - 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 fatch
  • remoteDataUrl - string; URL for send request to get data from server
  • headers - Object; the header for request of remote fatch
  • callback - 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

Package Sidebar

Install

npm i lobenton

Weekly Downloads

2

Version

1.1.1

License

MIT

Last publish

Collaborators

  • rexhome7326