In this section, we are going to create the MirageJS server and the routes that will be available. Follow these steps to create the server:
- Create a new file called server.js inside the src/server folder.
- Next, we need to import the Server class, the baseData, and the router methods:
import { Server } from 'miragejs';
import baseData from './db';
import { getFrom } from './get';
import { postFrom } from './post';
import { patchFrom } from './patch';
import { deleteFrom } from './delete';
- Create a global variable to the window scope, called server, and set this variable as a new execution of the Server class:
window.server = new Server({});
- In the Server class construction options, add a new property called seeds. This property is a function that receives the server (srv) as an argument and executes the srv.db.loadData function passing the baseDate as a parameter:
seeds(srv) {
srv.db.loadData({ ...baseData...