🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@nioh/proxy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nioh/proxy

proxy

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

Controller: proxy

安装

Install with npm

npm i @server/proxy --registry=http://npm.zkh360.com

说明

代理控制器,proxy

使用

import * as Koa from 'koa'
import * as Router from 'koa-router'
import * as body from 'koa-body'
import {proxy} from '@server/proxy'

const app = new Koa()
const router = new Router()

router.get('/', ctx => {
  ctx.body = 'context'
})

router.get('/api/somefile', body(), proxy({
  host: 'somehost',
  method: 'POST',
  type: 'stream',
  filename: 'demo.xlsx'
}))

router.all('/api/*', body(), proxy({
  debug: true,
  host: 'https://api.github.com',
  rewrite: {
    '^/api': '',
  },
  // 处理 request option, option 可参考 request 官方文档
  extend: (option, ctx) => {
    // option: request option
    option.headers.Authorization = `bearer ${ctx.state.token}`
  }
}))

app.listen(3000)

option

interface Option {
  host: string
  method?: string
  rewrite?: Object
  extend?: Function
  type?: string
  filename?: string
  debug?: Boolean
}

ChangeLog

Tests

npm test

License

2019@ZKH-FE

Keywords

proxy

FAQs

Package last updated on 12 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts