UNPKG

@zohodesk/client_build_tool

Version:

A CLI tool to build web applications and client libraries

62 lines (37 loc) 2.76 kB
# Mock Api ## Explanation:- This api is for run mock api. The reason for this feature is we usually run dev server as just to server react page not for api request. So when we need Mock Api or api request related this not on server (some java server). But do it in node js, this api. ## Ways to use Mock api There is two ways to run mock api. 1. Run mock api with dev server 2. Run mock api separate from dev server but api can be called through dev server. ### Run mock api with dev server In this way of running you do not need to run extra you do not have to run separate command. But every change you do in mock api you need to stop and restart. To run this you have to enable mock server and just un dev server as usual `cbt start` ### Run mock api separate from dev server This api is for run mock api in separate nodemon. So to run this you have to enable mock api and run `cbt mock:server`. ## Configuration To config this mock api you can need to add `mockServer` key in **cbt.config.js** or **package.json** file (`client-build-config` or `react-cli`) ==> `mockServer` | option | type | default | | :---------------: | :-----: | :--------------: | | enable | Boolean | false | | separateSeverPort | Number | null | | disableNodemon | Boolean | false | | mockEntryFile | String | mockapi/index.js | | mockPrefix | String | /api/ | ### **enable**: Specifies whether the application's mocking functionality is enabled or disabled. When set to `true`, the application will use the mock server. When set to `false`, the mock server will be disabled. By default, the value is set to `false`. ### **separateSeverPort**: Specifies the port to be used by the mock server. If the `enable` option is set to `true`, the application will use this port to run the mock server. This configuration parameter should be set to a valid port number. In this case, the port number is set to `8080`. ### **disableNodemon**: Specifies whether nodemon, a utility that automatically restarts the application upon file changes, should be disabled. When set to `true`, nodemon will be disabled. When set to `false`, nodemon will remain enabled. By default, the value is set to `false`. ### **mockEntryFile**: Specifies the entry file for the mock server. This file is the starting point for the mock server's execution. The value should be a string representing the file path. In this case, the entry file is set to `mockapi/index.js`. ### **mockPrefix**: Specifies the URL prefix for the mock server's API endpoints. The value should be a string representing the desired prefix. In this case, the prefix is set to `/api/`.