如果我
createServer
具有
幻影
,WDS(网页包开发服务器)断开连接。
如果我禁用mirages模拟服务器,WDS将正常工作。
下面是完整的调用堆栈
[WDS] Disconnected!
src/index。tsx
import { mockServer } from './server';
if (process.env.NODE_ENV === "development") {
mockServer({ environment: "development" });
}
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);
src/server。js
import { createServer, Response, Model } from 'miragejs';
export const mockServer = ({ environment = 'test' }) => {
createServer({
environment,
routes() {
this.namespace = "api";
this.post('/user/login', (schema, request) => {
return new Response(200, { }, { id: "admin@gmail.com", email: "qwerty", token: "Edovbkeyd2943kd3" });
});
},
});
}
export default mockServer;