鯨落筆記whale fall notes

內明學 adhyātmavidyā(意識學 Consciousness) |原始佛教 Pre-sectarian (Original) Buddhism|道教 Daoism (Taoism)|古瑜伽 Ancient Yoga|哲學 Philosophy|靈氣 Reiki|薩滿與民間信仰 Shaman & Folk Religions|太極 Tai Chi|氣功 Qi-Gong |軟件工程 Software Engineering

聯絡方式 contact: life.is.curiosity@pm.me


API Gateway in NodeJS

https://github.com/life-is-curiosity/js-apigateway

Feature

  1. API Rules
    Parameter checking
    Support regular-expression
  2. Distributed Load-Balancing Algorithms
    Random-Weighted Average Load-balancing algorithms to route the requests to different microservice endpoints.
  3. Asymmetric JWT Double-Lock Session
    Support private api, asymmetric key lock and basic session management
  4. Rate-Limit Components
    Able to customize the rate-limit for preventing the system loading
  5. Http API Proxy Gateway
    Http API redirect to other internal service endpoints
  6. Single Redis Instance
    Session or any persistance by Redis

Environment Construction

npm install or yarn install

Configuration

{
  "redis": {
    "host": "localhost",
    "port": 6379,
    "auth": "",
    "db": 0,
    "max_clients": 30,
    "tls": false
  },
  "rate_limit": {
    "interval_ms": "60000",
    "max_requests": "120"
  },
  "service_endpoints": {
    "timeout": 5000,
    "user": [
      {
        "hostname": "localhost",
        "port": 3001,
        "weight": 10
      },
      {
        "hostname": "localhost",
        "port": 3002,
        "weight": 2
      },
      {
        "hostname": "localhost",
        "port": 3003,
        "weight": 2
      },
      {
        "hostname": "localhost",
        "port": 3004,
        "weight": 4
      }
    ]
  },
  "session": {
    "algorithm": "RS256",
    "expire": 180
  }
}

Execution

pm2 start pm2.json --env local > /dev/null