cameronhunter / local-ssl-proxy

Simple SSL HTTP proxy using a self-signed certificate. Intended for local development only.
MIT License
686 stars 66 forks source link

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

Open theprojectsomething opened 1 year ago

theprojectsomething commented 1 year ago

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
nick-cromwell commented 1 year ago

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"
    }
momotofu commented 1 year ago

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

theprojectsomething commented 1 year ago

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).