Coder Social home page Coder Social logo

apiproxy's Introduction

apiProxy 异步接口反向代理

目的

旨在解决前端开发时无法跨域调用服务器接口,需要把代码部署到服务器上的问题,而开发的服务。

安装使用

进入项目,执行以下命令

npm install

开启服务

node apiProxy.js

设置代理参数

访问http://qinmudi.qq.com:9000/config?host=dev.erikqin.com&port=80
看到『恭喜设置成功,你的host:dev.erikqin.com,port:80』,表示设置成功!

  • host为代理服务器的地址,不加http
  • port为端口
  • 初始 host为dev.erikqin.com,端口为80
  • 设置以后所有的请求都会被转发到代理服务器

ajax调用

默认服务地址为 http://127.0.0.1:9000

$.ajax({
    url: 'http://127.0.0.1:9000/common/scenic/get_list_by_city_id',
    type: 'POST',
    dataType: 'json',
    data: {
        username: '王五',
        sex: '男',
        hobby: ['吃饭', '睡觉', '打豆豆']
    }
})
.done(function(res) {
    console.log(res);
})
.fail(function() {
    console.log("error");
})
.always(function() {
    console.log("complete");
});

apiproxy's People

Contributors

qinmudi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.