You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then, create a file named config-overrides.js, override webpack config using below codes:
156
+
157
+
```js
158
+
constapiMocker=require("connect-api-mocker"),
159
+
{ overrideDevServer } =require("customize-cra");
160
+
161
+
constdevServerConfig= () =>config=> {
162
+
return {
163
+
...config,
164
+
before: (app,server)=> {
165
+
//call cra before function to not break code
166
+
config.before(app, server);
167
+
//Then add our mocker url and folder
168
+
app.use(apiMocker('/api', 'mocks/api'));
169
+
}
170
+
}
171
+
}
172
+
173
+
module.exports= {
174
+
devServer:overrideDevServer(
175
+
devServerConfig()
176
+
)
177
+
};
178
+
```
179
+
Finally, change our run method to from "react-scripts start" to "react-app-rewired start" in package.json file:
180
+
```js
181
+
...
182
+
"scripts": {
183
+
"start":"react-app-rewired start",
184
+
...
185
+
}
186
+
...
187
+
```
150
188
### Using with other languages other than JavaScript
151
189
152
190
If you have a Python/Ruby/.NET etc. project and want to use that mocking functionality, you can use [cli-api-mocker](https://github.com/muratcorlu/cli-api-mocker) as a wrapper of connect-api-mocker for command line. With the help of cli-api-mocker, if you run `mockit` command, you will have a seperate web server that will handle your mocks as a REST API. Please look for [cli-api-mocker readme](https://github.com/muratcorlu/cli-api-mocker) for details.
0 commit comments