0.3.13 • Published 6 years ago

venustech-node-server v0.3.13

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

@venustech/server

build-status

Venustech frontend server based on Express.

In order to make it easy to manage so many service, we decide to make server as a indsividual package.

How to use

First install the package with npm install --save @venustech/server to install the server in the project. Then create a Server object in the start script. To start it successfully, you need some required config. And you can add external modules or routers on the server.

  • configPath(required) The config file path for default config loader
  • componentsList(required) The client app components list for html5mode support
  • webpackConfig(required) A method with return a webpack config object for optimize. We will pass config object as the first argument to the function.
  • externalModules
  • externalRouters

External Modules

The externalModules should be an array of custom modules. You can define your own module and the server will load it before optimize and http server started. Such as:

const externalModule = function(server, config, app) {
    /**
        server: The Venustech server object
        config: The server configs object. Use get() or set() to use it.
        app:    The Express app
    /
}

Every module will run asynchronously with the order of the externalModules array. So pay attention to the order of loaded modules.

External Routers

The externalRouters should be an array of custom routers. You can create your own router. Here is an example:

const createRouter = require('@venustech/server').createRouter;

const router = createRouter();

router.on('/example', (req, res, next) => {
    res.send('This is an example of external router');
});

module.exports = router;

The express app will run in the default router on express app. They will create with the order of routers. Be careful.