serve-middleware
v1.0.6
Published
A serve middleware with localize api mock and multi proxies
Downloads
2
Readme
serve-middleware
A serve middleware with localize api mock and multi proxies
Features
- Easy integrate and light api scheme definitions.
- Dynamic params routes and custom programming ability. eg,.
/api/foo/:id
- Built-in
typescript
types support. (ts-node manuall install required) - Auto reload and register mock routes. (w/o restart server when mock files changed)
- Pure json or any text based api mock. (optional supports mockjs extenssion)
- http-proxy-middleware proxy is integrated.
.proxy.json
,.proxy.js
Install
$ yarn add serve-middleware
APIs
import { middleware } from 'serve-middleware'
import express from 'express'
const app = express()
app.use(
middleware({
prefix: '/',
root: './mock'
})
)
Options
- root: The serve routes root directorty, need a absolute path.
- prefix: a baseurl for the server entry. eg:
/api
create .proxy.json
in project’s root: (json config support env vars expand)
{
"^/(api|image_pic_path)/": {
"target": "${API_PREFIX:-http://127.0.0.1:30006}",
"changeOrigin": true,
"pathRewrite": {
"^/api/": ""
}
},
"^/jaeger-ui": {
"target": "${JAEGER_UI_BASE:-http://127.0.0.1:3001}",
"changeOrigin": true,
"logLevel": "${PROXY_LOG_LEVEL:-info}"
}
}
Usage
For details example, see examples
License
MIT Copyright (c) Allex Wang