Настройка express шлюза для работы с redis - PullRequest
1 голос
/ 09 января 2020

Я настраиваю экземпляр шлюза express для маршрутизации запросов на микросервисы. Он работает, как и ожидалось, но я получаю следующие ошибки, когда я пытаюсь включить redis в конфигурацию моей системы

0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:policy] error: Failed to initialize custom express-session store, please ensure you have connect-redis npm package installed
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:gateway] error: Could not hot-reload gateway.config.yml. Configuration is invalid. Error: A client must be directly provided to the RedisStore
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:gateway] warn: body-parser policy hasn't provided a schema. Validation for this policy will be skipped.
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:policy] error: Failed to initialize custom express-session store, please ensure you have connect-redis npm package installed

Я установил необходимые пакеты

npm install redis connect-redis express-session

и обновил систему Файл .config.yml, например,

# Core
db:
  redis:
    host: ${REDIS_HOST}
    port: ${REDIS_PORT}
    db: ${REDIS_DB}
    namespace: EG

plugins:
  # express-gateway-plugin-example:
  #   param1: 'param from system.config'
  health-check:
    package: './health-check/manifest.js'
  body-parser:
    package: './body-parser/manifest.js'

crypto:
  cipherKey: sensitiveKey
  algorithm: aes256
  saltRounds: 10

# OAuth2 Settings
session:
  storeProvider: connect-redis
  storeOptions:
    host: ${REDIS_HOST}
    port: ${REDIS_PORT}
    db: ${REDIS_DB}
  secret: keyboard cat # replace with secure key that will be used to sign session cookie
  resave: false
  saveUninitialized: false
accessTokens:
  timeToExpiry: 7200000
refreshTokens:
  timeToExpiry: 7200000
authorizationCodes:
  timeToExpiry: 300000

Мой файл gateway.config.yml выглядит следующим образом

http:
  port: 8080
admin:
  port: 9876
apiEndpoints:
  accounts:
    paths: '/accounts*'
  billing:
    paths: '/billing*'

serviceEndpoints:
  accounts:
    url: ${ACCOUNTS_URL}
  billing:
    url: ${BILLING_URL}

policies:
  - body-parser
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit

pipelines:
  accounts:
    apiEndpoints:
      - accounts
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
    # - key-auth:
      - body-parser:
      - log: # policy name
        - action:    # array of condition/actions objects
        message: ${req.method} ${req.originalUrl} ${JSON.stringify(req.body)} # parameter for log action
      - proxy:
        - action:
            serviceEndpoint: accounts
            changeOrigin: true
            prependPath: true
            ignorePath: false
            stripPath: true
  billing:
    apiEndpoints:
      - billing
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
    # - key-auth:
      - body-parser:
      - log: # policy name
        - action:    # array of condition/actions objects
        message: ${req.method} ${req.originalUrl} ${JSON.stringify(req.body)} # parameter for log action
      - proxy:
        - action:
            serviceEndpoint: billing
            changeOrigin: true
            prependPath: true
            ignorePath: false
            stripPath: true

пакет. json

{
  "name": "max-apigateway-service",
  "description": "Express Gateway Instance Bootstraped from Command Line",
  "repository": {},
  "license": "UNLICENSED",
  "version": "1.0.0",
  "main": "server.js",
  "dependencies": {
    "connect-redis": "^4.0.3",
    "express-gateway": "^1.16.9",
    "express-gateway-plugin-example": "^1.0.1",
    "express-session": "^1.17.0",
    "redis": "^2.8.0"
  }
}

Я что-то упустил?

...