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 600
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

Former Community Member
Not applicable

Can you please paste more the config yaml file? I just tested this locally, it works for me.

NOTE: Your path has a mix of escape chars ('\\') and no escape chars ('\'). You may want to stick to one.

Thanks Srinandan,

I have below in my config file:

edge_config:
  bootstrap: >-
    https://edgemicroservices-us-east-1.apigee.net/edgemicro/bootstrap/organization/northwesternmutual/e...
  jwt_public_key: 'https://northwesternmutual-test.apigee.net/edgemicro-auth/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
  products: 'https://northwesternmutual-test.apigee.net/edgemicro-auth/products'
edgemicro:
  port: 8000
  max_connections: 1000
  max_connections_hard: 5000
  max_times: 300
  config_change_poll_interval: 600
  logging:
    level: error
    dir: /var/tmp
    stats_log_interval: 60                                  
    rotate_interval: 24
  plugins:
    sequence: 


targets:
  ssl:
    client:
      rejectUnauthorized: true
      key: C:\certs\client\apigee.key
      cert: C:\certs\client\apigee.crt
headers:
  x-forwarded-for: true
  x-forwarded-host: true
  x-request-id: true
  x-response-time: true
  via: true
<br>

Former Community Member
Not applicable

"targets" need to be under "edgemicro" stanza.

Thanks again for quick response.

Following the documentation, I was not clear on which level I should put the targets within config.yaml.

So, I put it under edgemicro and got no error on the start of microgateway, but when I tried to send a "GET" message to my target endpoint that has SSL enabled. I got error from the target service:

400 Bad RequestNo required SSL certificate was sent
<br>

Then I checked the microgateway-core/lib/config.js and below code seems to be getting the ssl details from config.targets and not config.edgemicro.targets.

Lines 12 -15 in file microgateway-core/lib/config.js:

configService.init = (newConfig) => {
  config = newConfig;
  config.edgemicro = config.edgemicro || { plugins: {} };
  config.targets = config.targets || [];
<br>

Also I did a console.log just above this line to check and got below output:

{ ssl:
   { client:
      { rejectUnauthorized: true,
        key: 'C:\\certs\\client\\apigee.key',
        cert: 'C:\\certs\\client\\apigee.crt' } } }
<br>

And I get blanks from this console.log when I include the targets under edgemicro.

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'