local-ssl-proxy icon indicating copy to clipboard operation
local-ssl-proxy copied to clipboard

config requires all parameters, including `key` and `cert` params

Open theprojectsomething opened this issue 1 year ago • 3 comments

Using a config.json (per the instructions) fails where all details aren't provided, e.g:

{
  "My proxy": {
    "source": 3001,
    "target": 3000
  },
  "Another proxy": {
    "source": 9999,
    "target": 9000
  }
}

throws an error:

node:internal/fs/utils:671
    throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.openSync (node:fs:577:10)
    at Object.readFileSync (node:fs:453:35)
    at Object.<anonymous> (node_modules/local-ssl-proxy/build/main.js:25:31)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'

Providing an SSL cert runs the proxy, but with undefined for the host:

Started My Proxy: https://undefined:3001 → http://undefined:3000

theprojectsomething avatar Mar 29 '23 02:03 theprojectsomething

I fixed this by including all parameters in config and making a cert using mkcert.

    "Host": {
        "source": 8080,
        "target": 8081,
        "key": "localhost-key.pem",
        "cert": "localhost.pem",
        "hostname": "localhost"
    }

nick-cromwell avatar May 18 '23 13:05 nick-cromwell

For more context, the following error is caused by passing null as a first argument to fs.readFileSync here: https://github.com/cameronhunter/local-ssl-proxy/blob/main/src/main.ts#L24

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or...

momotofu avatar Jul 13 '23 20:07 momotofu

Thanks @momotofu that's right. Tho I think the actual issue is that the parse method in .lib isn't returning sane defaults as expected.

Explicitly defining all the config params resolves the the issue. Using a locally issued cert is ideal, but if you're not worried about MITM then the cert provided with the package will also suffice (this is what the parse method is attempting to do).

theprojectsomething avatar Jul 13 '23 23:07 theprojectsomething