poetapp / frost-api

Po.et's API Layer
https://api.poetnetwork.net
MIT License
24 stars 5 forks source link

`poetUrl` not being honored by the environment variable set as `POET_URL` #491

Closed geoffturk closed 5 years ago

geoffturk commented 5 years ago

Wesley [13:19] @eng-team: so @geoffturk and I have been testing frost-api.qa today, we discovered an issue with poetUrl not being honored by the environment variable set as POET_URL, but only for the WorksController.create function. When trying to create a work, Frost API was failing to connect to node, as it was using the default value set, which is on the localhost / loopback interface:

{
  "timestamp": "2018-10-12T08:51:01.465Z",
  "level": "info",
  "message": {
    "monitor": {
      "method": "POST",
      "url": "/works",
      "headers": {
        "host": "frost-api.qa.poetnetwork.net",
        "accept": "*/*",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7",
        "content-type": "application/json",
        "referer": "https://app.swaggerhub.com/apis-docs/po.et/frost-api/0.1.0",
        "token": "[secure]",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
        "x-amzn-trace-id": "Root=1-5bc06070-464084d11c47a45ad4c0c6d1",
        "x-swaggerhub-cookie": "",
        "x-forwarded-for": "80.12.37.75, 10.101.10.132, 18.233.174.81",
        "x-forwarded-port": "443",
        "x-forwarded-proto": "https",
        "content-length": "151",
        "connection": "keep-alive"
      },
      "query": {},
      "params": {},
      "body": {
        "name": "string",
        "datePublished": "2018-10-12T08:28:01.997Z",
        "dateCreated": "2018-10-12T08:28:01.997Z",
        "author": "string",
        "tags": "string",
        "text": "string"
      }
    }
  }
}
{
  "timestamp": "2018-10-12T08:51:01.518Z",
  "level": "error",
  "type": "system",
  "message": "WorksController.create",
  "stackTrace": "FetchError: request to http://localhost:18080/works/ failed, reason: connect ECONNREFUSED 127.0.0.1:18080\n    at ClientRequest.<anonymous> (/usr/src/app/api/node_modules/node-fetch/lib/index.js:1345:11)\n    at ClientRequest.emit (events.js:182:13)\n    at Socket.socketErrorListener (_http_client.js:391:9)\n    at Socket.emit (events.js:182:13)\n    at emitErrorNT (internal/streams/destroy.js:82:8)\n    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)\n    at process._tickCallback (internal/process/next_tick.js:63:19)"
}

You can see that I have loaded the correct configuration as printed out when frost-api starts up:

{
  "timestamp": "2018-10-12T08:47:56.159Z",
  "level": "info",
  "message": {
    "vaultToken": "3yzLRVlZYfCvWMRN0VNcPz3S",
    "vaultUrl": "http://vault-vault-manual:8200",
    "vaultApiVersion": "v1",
    "mongodbUrl": "mongodb+srv://frost:mtHmdIWWExGjy9Gj@frost-api-staging-9hkw4.mongodb.net/frost",
    "mongodbSocketTimeoutMS": 0,
    "mongodbKeepAlive": 0,
    "mongodbReconnectTries": 30,
    "mongodbUseNewUrlParser": true,
    "poetUrl": "http://node-testnet-poet-node",
    "frostHost": "0.0.0.0",
    "frostPort": 3000,
    "frostUrl": "http://localhost:3000",
    "frostVerifiedAccount": "",
    "frostChangePassword": "",
    "verifiedAccount": true,
    "emailReply": "contact@po.et",
    "emailFrom": "Po.et",
    "sendEmailDisabled": false,
    "emailTransportMailDev": false,
    "maxApiTokens": 5,
    "maxApiRequestLimitForm": "500kb",
    "maxApiRequestLimitJson": "500kb",
    "passwordComplexMin": 10,
    "passwordComplexMax": 30,
    "passwordComplexLowerCase": 1,
    "passwordComplexUpperCase": 1,
    "passwordComplexNumeric": 1,
    "passwordComplexSymbol": 1,
    "pwnedCheckerRoot": "",
    "transactionalMandrill": "46mwv_E6dOxrSDUkJD4NOQ",
    "jwt": "2cff77d8f0a411e78c3f9a214cf093ae",
    "maildevPort25TcpAddr": "localhost",
    "maildevPort25TcpPort": 1025,
    "maildevIgnoreTLS": true,
    "redisPort": 6379,
    "redisHost": "redis-master",
    "rateLimitDisabled": false,
    "loginRateLimitMax": 1000,
    "accountRateLimitMax": 1000,
    "passwordChangeRateLimitMax": 1000,
    "loginRateLimitDuration": 3,
    "accountRateLimitDuration": 3,
    "passwordChangeRateLimitDuration": 3600000
  }
}

yet, WorksController was still trying to communicate with node on http://127.0.0.1:18080 to get around this, I created a new branch, and changed the configuration to this: https://github.com/poetapp/frost-api/blob/bug/node-loopback/src/configuration.ts#L77 frost-api WorksController.create was then communicating to the correct node now and we were not getting any more errors, and were able to create works https://frost-api-testing.qa.poetnetwork.net contains the fix I made https://frost-api.qa.poetnetwork.net is running with v1.3.0 which will cause errors so theres def something funky happening with the configuration

poet-ci commented 5 years ago

:tada: This issue has been resolved in version 1.3.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: