Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

⚡ The one-liner node.js http-proxy middleware for koa2

License

NotificationsYou must be signed in to change notification settings

fengxinming/koa2-simple-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: thatkoa2-simple-proxy supports for koa2Note: 对http-proxy的简易封装,支持koa2


Features

Framework

  • Node >= 7.6
  • Koa >= 2.0

Usage

$ cnpm install koa2-simple-proxy --save

Development

Note: if you use [/api and/api2] as prefixes, the/api2 should be in front of the/api

const Koa = require('koa');const proxy = require('koa2-simple-proxy');const app = newKoa();// x-response-timeapp.use(async(ctx, next) => {  const start =Date.now();  awaitnext();  const ms =Date.now() - start;  ctx.set('X-Response-Time',`${ms}ms`);});// loggerapp.use(async(ctx, next) => {  const start =Date.now();  awaitnext();  const ms =Date.now() - start;  console.log(`${ctx.method}${ctx.url} -${ms}`);});// proxyapp.use(proxy('/rest','http://192.168.1.240/api2'));app.use(proxy(['/api2','/api'],'http://192.168.1.240/api2'));app.use(proxy('/api3','http://192.168.1.240/api2', {  events: {    error(err, req, res) {      res.writeHead(500, err.message, {'Content-Type':'application/json'      });      res.end(JSON.stringify(Object.assign({}, err, {        message: err.message, // 有时候message字段不能被输出        url: req.url      })));    }  }}));// responseapp.use(async ctx => {  ctx.body ='Hello World';});app.listen(9527, () => {  console.log(`Listening on 9527`);});

About

⚡ The one-liner node.js http-proxy middleware for koa2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp