Git Product home page Git Product logo

uuaper's Introduction

Uuaper

NPM Version NODE Version OSX Build LINUX Build

Proxy tool based on NodeJS for front-end development.

Feature

  • 前后端分离,前端会有跨域问题,本工具提供server端proxy :)
  • baidu uuap 自动登录

Install

    npm install --save-dev uuaper

配置项

name detail
targer proxy url
debug default: false
headers request headers
mock mock local files, default: false
cache cache dir, only cache content-type is json request
server build-in server settings, include(port, staticPath, proxyPath)
auth auth logic

auth

name detail
getAuth(cb) you auth logic
forwardCookie(cb) before make sure cookie
retry(res, data) retry logic
baidu auth setting baidu uuap auth bird-auth

Usage

自定义headers & 启动server

const uuaper = require('uuaper');
const uuap = new uuaper({
    target: 'http://xxx.xxx.com/',
    headers: {
        cookie: 'xxx'
    },
    debug: true,
    server: {
        port: 1337,
        staticPath: __dirname,
        proxyPath: ['/aaa'] // 需要转发的context路径,譬如/aaa下面的所有请求都走proxy
    }
});

结合express使用实现接口转发功能

const express = require('express');
const app = express();

const uuaper = require('uuaper');
app.use('/api', new uuaper({
    target: 'http://xxx.baidu.com/',
    debug: true,
    headers: {
        refer: 'http://xxx.com'
    },
    cache: './cache'
}));

baidu uuap 自动认证

const uuaper = require('uuaper');
const uuap = new uuaper({
    target: 'http://xxx.xxx.com/',
    auth: {
        username: 'xxx',
        password: 'xxx',
        server: 'http://xxx.xxx.com/login?service=xxxx',
        retry: function(res, data) {
            return +res.statusCode === 403;
        }
    }
});

baidu passport 自动认证

const uuaper = require('uuaper');
const uuap = new uuaper({
    target: 'http://xxx.xxx.com/',
    auth: {
        type: 'passport',
        username: 'xxx',
        password: 'xxx',
        server: 'https://passport.qatest.xxx.com/', //default passport.xxx.com
        forwardCookie: function (cb) {
            // use `uuaper.client` do something to get extrenal cookie
            uuaper.client.get('xxx.baidu.com', function () {
                cb && cb(uuaper.client.get_cookies_string());
            });
        }
    }
});

TODO(很久很久之前的)

  • mock 支持带参数的url
  • cache 支持多类型
  • bprouting 302 deal
  • 支持配置项
  • 数据mock
  • mock no cache
  • 静态资源文件proxy
  • Do more...

History

  • [3.1.0] 修复重构代码导致的runProxy错误,移除es-promise和fs-path包。
  • [3.0.0] update new auth.
  • [2.0.9] update bird-auth.
  • [2.0.8] fix fsPath.writeFile error
  • [2.0.7] add request body size limit setting
  • [2.0.6] 支持自定义 auth logic
  • [2.0.5] 增加baidu.passport支持 & headers bugfix
  • [2.0.0] 配置项优化
  • [1.3.4] content-type处理优化
  • [1.3.3] 增加content-typestream判断
  • [1.3.1] rejectUnauthorized: false处理https证书问题
  • [1.3.0] 重构proxy模块,也许是该项目最大的一次重构
  • [1.2.6] res.headers原封不动返回,来解决流形式响应
  • [1.2.3] 增加cookie参数,如果配置,就不使用默认的uuap自动获取方式
  • [1.1.0] 增加接口数据mock功能
  • [1.0.x] 重构,使用bird-auth包进行cookie获取,同时优化内置server
  • [0.1.7] 老版本

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.