1.0.17 • Published 7 years ago

@horwood/server v1.0.17

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@horwood/server

This is a simple Node.js module that allows the user to quickly bootstrap a server utilising the Express framework.

Getting Started

It is available through the NPM registry by using the following command:

$ npm install @horwood/server

Running via the CLI

In order to run the server from the CLI, run:

$ horwood-server

The server must be provided with a server.conf module in order to function. By default, it looks in the root directory of your project for a module named server.conf. If you wish to override this, you can use the following command:

$ horwood-server --server-conf=./path/to/server.conf

Running Programmatically

To run the server programmatically, you must call Server.start using a valid ServerConf.

const horwoodServer = require('@horwood/server');
const serverConf = new horwoodServer.ServerConf(require('./server.conf'));
horwoodServer.Server.start(serverConf);

Configuration

Configuration should be provided using the following format:

const port = 8080;
const serverConf = {
  'logConf': {
    'location': './logs',
    'preserve': false,
    'level': 'INFO'
  },
  'endpoints': [
    {
      'method': 'GET',
      'path': '/',
      'callback': (req, res) => {
        res.json(serverConf.endpoints)
      }
    }
  ],
  'port': port,
  'prefix': '/api',
  'staticConf': {
      'prefix': '',
      'root': 'dist'
  },
  'proxies': [
      {
          'path': 'endpoints',
          'destination': `http://localhost:${port}/api`
      }
  ],
  'sockets': true,
  'socketsCallback': (io) => {
      io.on('connection', (socket) => {
         socket.emit('testEvent'); 
      });
  }
};
module.exports = serverConf;

Valid configuration properties are listed below.

PropertyDescriptionOptionsDefault
logConf.locationWhere log files will be stored../logs
logConf.preserveWhether or not to preserve old logs.true falsefalse
logConf.levelThe level of logs to output.VERBOSE INFO WARN ERRORINFO
endpointsA list of endpoints to be mapped.[]
endpoint.methodThe HTTP method to use for the endpoint.DELETE GET POST PUT
endpoint.pathThe path to use for the endpoint.
endpoint.callbackThe function to call when the endpoint is hit.
portThe port to deploy the server on.8080
prefixThe prefix to prepend all endpoints with./api
staticConf.prefixThe prefix to prepend to requests for static content.
staticConf.rootThe root of the static content.
proxiesA list of proxies to be configured.[]
proxy.pathThe path to use for the proxy.
proxy.destinationWhere to send the request to when the path is hit.
socketsA flag stating whether sockets should be enabled.true falsefalse
socketsCallbackA callback that is called when Socket IO is ready.
1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.1

7 years ago