microgateway 一些参考资料

microgateway 是apigee 开源的自家edgemicro gateway,目前github 上的信息不是很全,以下是一些整理

配置

microgateway 是需要配置管理的,但是github相关文档很少,如果需要参考(合理上网)
https://docs.apigee.com/api-platform/microgateway/edge-microgateway-home,最好还是看下官方文档

  • 一个参考配置
    注意此配置部分的plugin 是基于官方的,实际我们如果直接使用microgateway-core,plugin 部分需要调整下
 
edge_config:
  bootstrap: https://apigee.net/edgemicro/bootstrap/organization/org/environment/env...
  jwt_public_key: http://apigee.net/edgemicro/publicKey...
  managementUri: https://api.enterprise.apigee.com
  vaultName: microgateway
  authUri: https://%s-%s.apigee.net/edgemicro-auth
  baseUri: https://edgemicroservices.apigee.net/edgemicro/%s/organization/%s/environment/%s
  bootstrapMessage: Please copy the following property to the edge micro agent config
  keySecretMessage: The following credentials are required to start edge micro
edgemicro:
  port: 8000
  max_connections: 1000
  config_change_poll_interval: 600
  logging:
    level: error
    dir: /var/tmp
    stats_log_interval: 60
    rotate_interval: 24
    stack_trace: false
  plugins:
    sequence:
      - oauth
headers:
  x-forwarded-for: true
  x-forwarded-host: true
  x-request-id: true
  x-response-time: true
  via: true
oauth:
  allowNoAuthorization: false
  allowInvalidAuthorization: false
  gracePeriod: 10
 
 

扩展插件

这个github 上也已经开源了,同时也已经提供了很多,可以直接使用,具体每个插件的配置进入插件目录就可以看了
参考https://github.com/apigee/microgateway-plugins ,如下https://github.com/apigee/microgateway-plugins/tree/master/extauth
readme 就包含了插件的使用,注意有些可能没有,但是插件的模型很简单,看看代码也行,如果看了官方edgemicro的代码,内置插件 
的注册就是类似如下模式注册的

  • 一个参考plugin 的使用
    package.json
 
{
  "name": "edge-gayeway",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "config": "^3.3.1",
    "debug": "^4.1.1",
    "microgateway-core": "^3.1.4",
    "microgateway-plugins": "^3.0.14"
  },
  "scripts": {
    "start": "DEBUG=* node app.js"
  }
}

配置
config/default.yaml

 
edgemicro:
  port: 3000
  logging:
    level: warn
proxies:
- base_path: /
  url: http://localhost:8080
 

代码引用plugin

'use strict'
const debug = require('debug')('test')
const microgateway = require('microgateway-core')
// 引用内置的cors plugin
const cors = require("microgateway-plugins/cors")
const config = require('config')
const gateway = microgateway(config)
debug('starting gateway')
// 添加plugin
gateway.addPlugin("cors",cors.init)
console.log("plugins",gateway.plugins.toString())
gateway.start((err, server) => {
  if (err) {
    debug('gateway err %o', err)
    process.exit(1)
  }
  debug('gateway started')
})

说明

目前microgateway文档不是很全,但是整体代码不难,我们可以参考学习下

参考资料

https://www.npmjs.com/package/edgemicro
https://github.com/apigee/microgateway-core

posted on 2020-05-31 17:39  荣锋亮  阅读(696)  评论(0编辑  收藏  举报

导航