This project is a simple mock server management interface built with React and Express. It allows users to create, update, delete, and manage mock API routes. The frontend is built using React with Vite as the build tool, while the backend is a simple Express server that stores mock data in a JSON file.
- Add New Routes: Users can add new mock routes by specifying the path, HTTP method, response, and description.
- Edit Existing Routes: Users can edit existing routes to update their path, method, response, or description.
- Delete Routes: Users can delete routes that are no longer needed.
- Search Routes: Users can search for routes by path, method, or description.
- Dynamic Mock Responses: The server dynamically responds to requests based on the configured mock routes.
-
Frontend: The React application is located in the
srcdirectory.App.jsx: The main application component that manages the state and routing.RouteForm.jsx: A form component for adding or editing mock routes.RouteList.jsx: A component that displays the list of mock routes.Sidebar.jsx: A sidebar component that includes the search functionality and the list of routes.dev.js: A script to start both the mock server and the Vite development server.
-
Backend: The Express server is located in the
src/serverdirectory.index.js: The main server file that handles CRUD operations for mock routes and serves mock responses.
- Node.js (v20 or higher)
- npm or yarn
-
Clone the repository:
git clone https://github.com/lpcv5/mockserver-ui.git cd mockserver-ui -
Install dependencies:
npm install
-
Start the development environment:
npm run dev
This will start both the mock server and the Vite development server.
- Mock Server: The mock server will run on
http://localhost:3000. - Vite Dev Server: The React application will run on
http://localhost:5173.
npm run dev: Starts both the mock server and the Vite development server.npm run build: Builds the React application for production.npm run serve: Serves the production build of the React application.
-
Add a New Route:
- Click the "Add New Route" button in the sidebar.
- Fill in the path, method, response (JSON), and description.
- Click "Add Route" to save the new route.
-
Edit an Existing Route:
- Click on a route in the sidebar to select it.
- Modify the route details in the form.
- Click "Save Changes" to update the route.
-
Delete a Route:
- Select a route from the sidebar.
- Click the delete button (not shown in the current code, but can be added).
-
Search Routes:
- Use the search bar in the sidebar to filter routes by path, method, or description.
- GET
/admin/mock: Fetch all mock routes. - POST
/admin/mock: Add a new mock route. - PUT
/admin/mock/:id: Update an existing mock route. - DELETE
/admin/mock/:id: Delete a mock route.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.