Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neki-dev/moccu
📟 Easy mock server for front-end applications
https://github.com/neki-dev/moccu
api fake mock proxy response serve server
Last synced: 13 days ago
JSON representation
📟 Easy mock server for front-end applications
- Host: GitHub
- URL: https://github.com/neki-dev/moccu
- Owner: neki-dev
- License: mit
- Created: 2024-12-16T23:25:38.000Z (17 days ago)
- Default Branch: main
- Last Pushed: 2024-12-16T23:54:42.000Z (17 days ago)
- Last Synced: 2024-12-17T00:45:08.522Z (17 days ago)
- Topics: api, fake, mock, proxy, response, serve, server
- Language: TypeScript
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 📟 Moccu
[![Npm package version](https://badgen.net/npm/v/moccu)](https://npmjs.com/package/moccu)Simple mock server for front-end applications
.
* ## Install
```sh
npm i moccu --save-dev
```.
* ## Run
Run the server by command
```sh
moccu
```.
* ## Configuration
Create and configure `moccu.config.ts` file at project root. Or it will created automatically on the first start.
```ts
import type { Config } from 'moccu';const config: Config = {
/**
* Server port
*/
port: 3000,/**
* API url prefix
*/
base: '',/**
* List of mocked routes
*/
routes: [],/**
* Display logs
*/
log: true,
};export default config;
```.
* ## Mock route
#### 1. Create mocked route
`./__mocks__/get-user.ts`
```ts
import type { Route, Request } from 'moccu';const route: Route = {
/**
* Request path
*/
path: '/user/:userId',/**
* Request method
*/
method: 'get',/**
* Response status
*/
status: 200,/**
* Response body
*/
response: (req: Request) => {
return {
text: `Hello, ${req.params.userId}`,
};
},/**
* Response delay
*/
delay: 100,
};export default route;
```#### 2. Import mocked route to global config
`./moccu.config.ts`
```ts
import type { Config } from 'moccu';import getUser from './__mocks__/get-user';
const config: Config = {
port: 3000,
base: '/api',
routes: [
getUser,
],
};export default config;
```