Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli doesn't respect dotenv in same location as *.http file #112

Closed
staff0rd opened this issue Nov 17, 2021 · 2 comments
Closed

cli doesn't respect dotenv in same location as *.http file #112

staff0rd opened this issue Nov 17, 2021 · 2 comments

Comments

@staff0rd
Copy link
Contributor

Docs suggest that:

The .env files are searched from the following locations:

  • same location as *.http file

For the following files:

# spacex.http
GET {{HOST}}/launches/latest HTTP/1.1

# dev.env
HOST=https://api.spacexdata.com/v4

If I place these in the root of a git repo, then the following command works:

httpyac spacex.http --all -e dev

However, I move the files to a child of the root, for example, <repo>/test, running the command above from the test folder throws:

ReplaceVariableHook: javascript failed
BeforeRequestHook: requestVariableReplacer failed
{{HOST}}/launches/latest {
  url: '{{HOST}}/launches/latest',
  method: 'GET',
  http2: false,
  headers: {},
  cookieJar: CookieJar {
    rejectPublicSuffixes: true,
    enableLooseMode: false,
    allowSpecialUseDomain: false,
    store: { idx: {} },
    prefixSecurity: 'silent',
    _cloneSync: [Function (anonymous)],
    _importCookiesSync: [Function (anonymous)],
    getCookiesSync: [Function (anonymous)],
    getCookieStringSync: [Function (anonymous)],
    getSetCookieStringsSync: [Function (anonymous)],
    removeAllCookiesSync: [Function (anonymous)],
    setCookieSync: [Function (anonymous)],
    serializeSync: [Function (anonymous)]
  },
  proxy: undefined
} ReferenceError: HOST is not defined
    at Object.<anonymous> (spacex.http:3:20)
    at Me (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:18161)
    at z (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:18526)
    at Object.jo [as action] (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:2:43344)
    at wt.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3409)
    at async me (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:27307)
    at async Object.Qr [as action] (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:55373)
    at async be.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3392)
    at async ie (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:14816)
    at async $e.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3392)
ExecuteHook: httpClient failed
ReferenceError: HOST is not defined
    at Object.<anonymous> (spacex.http:3:20)
    at Me (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:18161)
    at z (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:18526)
    at Object.jo [as action] (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:2:43344)
    at wt.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3409)
    at async me (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:27307)
    at async Object.Qr [as action] (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:55373)
    at async be.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3392)
    at async ie (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:14816)
    at async $e.trigger (/home/stafford/.nvm/versions/node/v14.17.0/lib/node_modules/httpyac/dist/index.js:1:3392)

I think it's because this code is passing context.httpFile.rootDir, but I don't understand the relevance of rootDir at that position.

I also note that the vscode extension does not have this issue. The environment is selectable even under /test and the send suceeds.

@AnWeber
Copy link
Owner

AnWeber commented Nov 17, 2021

contect.httpFile.rootDir is undefined. Workaround would be to put a empty .httpyac.js next to the dev.env file. This code location differs between the VSCode extension and the CLI. VSCode always returns absolute File URIs, the CLI only relative ones. For this reason I use rootDir to generate an absolute URI again, but there I have a thinking error in it. I just noticed another constellation that would lead to a bug. Probably the easiest fix would be to convert the fileName in the CLI case to an absolute URI as well, but that needs to be looked at more closely.

@AnWeber
Copy link
Owner

AnWeber commented Nov 17, 2021

I have now fixed the error by always converting the filename to an Absolute Uri. The bug fix is released with v4.7.1

@AnWeber AnWeber closed this as completed Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants