Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error when starting edgemicro with targets.ssl.client setting for TLS "config.targets.forEach is not a function"

Not applicable

For edgemicro version 2.4.6.

I get the error "config.targets.forEach is not a function at Object.configService.init" when I start edgemicro after configuring for mutual TLS to backend service. below are logs from cmd:

C:\Users\user\AppData\Roaming\npm\node_modules\edgemicro\node_modules\microgateway-core\lib\config.js:28
  config.targets.forEach(function(target) {
                 ^


TypeError: config.targets.forEach is not a function
    at Object.configService.init (C:\Users\user\AppData\Roaming\npm\node_modules\edgemicro\node_modules\microgateway-core\lib\config.js:28:18)
<br>

-------------------------------------------------------------------------------------------------------------

config.yaml file:

targets:  
  ssl:
    client:
      rejectUnauthorized: true
      key: C:\certs\client\apigee.key
      cert: C:\certs\client\apigee.crt

The error is in the microgateway-core module and I am following the instructions a this link:

http://docs.apigee.com/microgateway/latest/operation-and-configuration-reference-edge-microgateway#u...

Solved Solved
0 5 646
1 ACCEPTED SOLUTION

The error referencing the forEach() function leads me to believe that the code is expecting an array instead of an object. You can create the same error easily yourself by running the following test:

{"foo":"bar"}.forEach(function(f){console.log(f);});

In YAML, an array type indicated as a list prefixed by '-', so I would expect the following:

targets:
  - host: "www.google.com"
    ssl:
      (other configs)

I agree this is not what the documentation says, but it is what is in the github ticket when this was implemented:

(below from https://github.com/apigee/microgateway-core/issues/9)

targets:
  - host: 'example.com'
    ssl:
      client:
        key: '/location/of/key'
        cert: '/location/of/cert'
        ca: '/location/of/ca'

View solution in original post

5 REPLIES 5