Skip to content
This repository was archived by the owner on Sep 23, 2022. It is now read-only.
M ABD AZIZ ALFIAN edited this page Jan 9, 2020 · 21 revisions

Sorry, this documentation is still on progress to write.


Welcome to the cluster-static-server wiki!

Table Of Contents

Get Started

  1. Clone or Download this repo.
  2. Extract it.
  3. Go to the extracted directory.
  4. Run $ npm install.
  5. Done

How to run the server

  • To start master server $ npm run master.
  • To start node server $ npm run node.

Note :

  • You are able to start master and node server in same machine server with different port. But, actualy Master and Node server should be on different machine server so you will get the best performance.

Back to top

Example Case

Assume you have already 3 machine server.

  • Master is on 10.0.0.11:3000
  • Node 1 is on 10.0.0.12:3001 >> give it prefix name with /ns1
  • Node 2 is on 10.0.0.13:3002 >> give it prefix name with /ns2

Because static server is for public use, so you have to set domain name for Master server.

10.0.0.11 >> static.yourdomain.com
10.0.0.12 >> no need to have a domain
10.0.0.13 >> no need to have a domain

Configuration Master

See example configuration based case above.

// all this config is required
const config_master = {

    // x_token header authentication for master API
    x_token: '12345678',

    // x_token header authentication for node API
    node_x_token: '87654321',

    // set origin for master server
    // Origin is the full base url of master server.
    // You can change this origin with domain name like http://yourdomain.com
    origin: 'http://static.yourdomain.com', // without trailing slash

    // set this master server port
    masterPort: 3000,

    // node server list
    nodeServer: [ // you can add more node server
        { upstream:'http://10.0.0.12:3001', prefix:'/ns1', http2: false },
        { upstream:'http://10.0.0.13:3002', prefix:'/ns2', http2: false }
    ],

    // Limit upload size
    limitSize: (50 * 1024 * 1024), // 50Mb

    // Block upload to spesific node destination. 
    blockNode: [], // Ex. ['/ns2','/ns3'] means the file will not upload to /n2 and /ns3.

    // Print the log
    logger: true
    
}

module.exports = config_master;

Configuration Node

Remember that Node 1 prefix name is /ns1 and Node 2 prefix name is /ns2. So you only have to set nodePrefixName in config-node.js. And check for the nodePort.

Example for Node 1:

    // set node prefix name for this node server
    nodePrefixName: '/ns1', // without trailing slash but leading slash is required

    // set node port for this node server
    nodePort: 3001,

Example for Node 2:

    // set node prefix name for this node server
    nodePrefixName: '/ns2', // without trailing slash but leading slash is required

    // set node port for this node server
    nodePort: 3002,

Back to top

Limitation

This cluster-static-server project was design for flexible to use or to fork. Also I want to keep this project always minimalis, so there is bit limitations in this project :

  • No Database
    This cluster-static-server project is only static server, so there is no any database required.
  • No Authentication
    I did not implement any authentication in this project because I want you to be more flexible to choose any kind of authentication method for your business application. Actualy for simple authentication by header is already implemented in this project. Just improve it or create it by yourself.
  • No Update File
    Naturaly a static server will serve "as it" file to your browser with long cache expiring time. So update file feature could be useless for static server. But you can create your own application to manage your file with this cluster-static-server API.

Back to top

Clone this wiki locally