@bracken/noodles

1.6.5 • Public • Published

For Gitlab viewers :

Before your following steps to add this package as a npm depedency,you should set local npm registry first.

npm set registry http://npm.decobim.com
npm adduser --registry http://npm.decobim.com

Noodles

CocoaPods Hackage-Deps

A node middle layer for proxy, websocket, api polymerization and request side effects.

Demo usage in ./exec

Get Started

install as depedency with yarn

$ yarn add @decobim/noodles

Bootstrap noodles host server

const noodles = require("@decobim/noodles")

// noodles-sockets & noodles-redis are depedencies of noodles,
// you can require them directly
const sockets = require("@decobim/noodles-sockets");
const redises = require("@decobim/noodles-redis");

noodles(
  port: 9020,

  static: path.resolve(__dirname, "./public"),

  redis: {
    localhost: "redis://:@localhost/0"
  },

  proxy: {
    ops: {
      from: "/operation/v1",
      to: "http://dev.api.ops.decobim.com/v1/",
      hooks: {
        before: {
          "/identity/auth": function(req, res) {}
        },
        after: {
          "/identity/auth": function(req, res) {}
        }
      }
    },
    license: {
      from: "/license/v1",
      to: "http://dev.api.license.decobim.com/v1/"
    }
  },
  sockets: {
    channels: ["first", "second", "third"]
  },
  jwt: {
    authlessApi: [
      "/identity/auth",
      "/identity/project-quest-auth",
      "/identity/wechat-auth",
      "/admin/auth"
    ]
  }
})

Docs

configs.port

configs.static

optional

configs.redis

optional

redis config, each record will create a redis connection instance

format:

redis:{
  [name]:[redis address]
}

All instances can be accessed with redises[name]

const redises = require("noodles-redis")

redises[name].set("key","value")

redis instance properties:

Property Description Demo
set set redis value instance.set(key:string,value:any)
get get value instance.get(key:string)
del delele redis record instance.del(key:string)
on attach redis sub listener instance.on(channel:string,callback:func)

configs.proxy

optional

server proxy config, each record will create a a to b proxy mapping,and attach origin request method to noodles.clients.

format

proxy:{
 [name]:{
    from:[from path],
    to:[target url],
    hooks:{
      before:{
        [path]:callback
      },
      after:{
        [path]:callback
      }
    }
  }
}

proxy client properties

configs.sockets

optional

configs.sockets.channels

configs.jwt

optional

configs.jwt.authlessApi

Readme

Keywords

Package Sidebar

Install

npm i @bracken/noodles

Weekly Downloads

1

Version

1.6.5

License

ISC

Unpacked Size

40.2 kB

Total Files

19

Last publish

Collaborators

  • bracken