serve-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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

Package Sidebar

Install

npm i serve-middleware

Weekly Downloads

4

Version

1.0.6

License

MIT

Unpacked Size

28.5 kB

Total Files

18

Last publish

Collaborators

  • allex