@diginet/cors-proxy
TypeScript class implementing a proxy server with CORS providing GET and POST access to servers without CORS.
Last updated 2 years ago by anderswestberg .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @diginet/cors-proxy 
SYNC missed versions from official npm registry.

CorsProxy

TypeScript class implementing a proxy server with CORS providing GET and POST access to servers without CORS.

Installation

npm install @diginet/cors-proxy --save

Usage

CLI

Create proxy server

import { CorsProxy } from "../CorsProxy"

const corsProxy = new CorsProxy("127.0.0.1", 8787, console.log)
/**
 * Constructor
 * @param host The interface (IP) to host the server
 * @param port Server port
 * @param log Optional log function with a string argument
 */
constructor(public host: string, public port: number, private log?: (message: string) => void)

Call from web client

Request

const url = "http://127.0.0.1:8787/get?url=" + encodeURIComponent("https://some.server/something")
request(url, (error, response, body) => {
    if (!error)
    	console.log(body)
    else
        console.log(error)
})

AJAX

var url = "https://some.server/something";
$.ajax({
        type: 'GET',
        accepts: 'application/json',
        url: "http://127.0.0.1:8787/get?url=" + encodeURIComponent("https://some.server/something"),
        contentType: 'application/json',
        error: function (jqXHR, textStatus, errorThrown) {
            alert('error');
        },
        success: function (result) {
            console.log(result);
        }
    });

Using Postman

To encode the url query parameter correctly, select the URL parameter content, right-click and select EncodeURIComponent.

Current Tags

  • 1.1.9                                ...           latest (2 years ago)

9 Versions

  • 1.1.9                                ...           2 years ago
  • 1.1.8                                ...           2 years ago
  • 1.1.7                                ...           2 years ago
  • 1.1.5                                ...           2 years ago
  • 1.1.4                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 10
Last Day 0
Last Week 9
Last Month 7
Dependencies (11)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |