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

Advice: add mocker api config like mocker.config.js #144

Closed
vanpipy opened this issue Oct 26, 2020 · 14 comments
Closed

Advice: add mocker api config like mocker.config.js #144

vanpipy opened this issue Oct 26, 2020 · 14 comments

Comments

@vanpipy
Copy link
Contributor

vanpipy commented Oct 26, 2020

Hi, I used the independent mode like mocker mock/index.js and found that the host and port cannot change in this mode. So I feel it's not easy to use as a part of a project. Try to get the HOST and PORT from a config file will be better than using the process.env.

Is this useful or need that?

Thanks.

@jaywcjlove
Copy link
Owner

@vanpipy I don't know what you are going to do.

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 27, 2020

Because the implementation is:

const HOST = process.env.HOST || '0.0.0.0';

Like this

-   mocker mock/index.js
+   mocker --config mocker.config.json mock/index.js // or
+   mocker mock/inde.js // search the mocker.config.json in the project defaulty

And the user can set the HOST and PORT as wish.

Is that necessary?

@jaywcjlove
Copy link
Owner

@vanpipy Support mocker mock/m1.js test/m2.js

jaywcjlove added a commit that referenced this issue Oct 27, 2020
@jaywcjlove
Copy link
Owner

@vanpipy Upgrade + mocker-api@2.4.0

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 27, 2020

Hi, @jaywcjlove ,

I got your idea, the next PR will upgrade the version and the document together.

@jaywcjlove
Copy link
Owner

@vanpipy Already supported.

  • Support command line multi-file listeners 2c4dd5c

@jaywcjlove
Copy link
Owner

@vanpipy Support setting configuration on package.json?

{
  ...
  "mocker": {
    "host": "127.0.0.1",
    "port": 7788
  }
}

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 27, 2020

@vanpipy Support setting configuration on package.json?

{
  ...
  "mocker": {
    "host": "127.0.0.1",
    "port": 7788
  }
}

That is a better choice :D.

And a result needs to figure out which one is the first config for the user.

I suggest the priority:

  1. from the command line.
  2. from the package.json.
  3. from the mocker.config.json.

jaywcjlove added a commit that referenced this issue Oct 27, 2020
@jaywcjlove
Copy link
Owner

jaywcjlove commented Oct 27, 2020

@vanpipy Support setting parameters:

mocker mock/index.js --port 7788
mocker mock/index.js --host 0.0.0.0

help:

Usage: mocker <path> [--config] [--help|h]

Displays help information.

Options:
  --config <path> Simple configuration

Example:
  mocker mock/index.js
  mocker mock/index.js --port 7788
  mocker mock/index.js --host 0.0.0.0
  mocker mock/m1.js test/m2.js
  mocker mock/m1.js --config mocker.config.json

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 27, 2020

Hi, @jaywcjlove ,

Yes, --host and --port is useful, and the usage needed.

@jaywcjlove
Copy link
Owner

Hi @vanpipy

I hope to help improve the documentation when I have time, thank you!

Command line supports more parameter configuration:

{
  ...
  "mocker": {
    "host": "127.0.0.1",
    "port": 7788,
    "pathRewrite": {
      "^/api/repos/": "/repos/"
    },
    "changeHost": true,
    ...
  }
}

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 29, 2020

Summary:

The mocker command line support 3 parameters:

  1. --host localhost
  2. --port 8000
  3. --config ./mocker.config.json

Of course, the -h and --help is in the house already.

And the priority of the config - assuming three configurations exist already.

  1. Local mocker config like mocker.config.json.
  2. The config in the package.json like:
{
    "mocker": { ... }
}
  1. The parameters from the command line.

First, the mocker commander will try to find the mocker.config.json. If exists and overwrite the default config.
Second, try to take the mocker from package.json. If exists and overwrite again.
Third, try to take host and port from the command line and overwrite the host and port.

That is all things of the mocker command line doing.

@jaywcjlove
Copy link
Owner

jaywcjlove commented Oct 29, 2020

@vanpipy thx! Released mocker-api@2.7.0

@vanpipy
Copy link
Contributor Author

vanpipy commented Oct 30, 2020

The issue resolved, so close it.

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