🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

connect-json-proxy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-json-proxy

grunt-connect middleware to proxy API requests to remote servers without CORS or JSONP. Based on the json-proxy project, for express.

1.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

Intro

This is a simple package that wraps the json-proxy package, providing support for multiple endpoints based on an HTTP Header or URL parameter.

It fulfils a specific need for internal applications for us, so is NOT designed to be super high performance or on production sites. (for example, it re-initializes the proxy for EVERY request).

Usage

Assuming that grunt-connect us running on port 9000, and you can call the following URL to get the connect server to redirect the request to somewhere else.

http://localhost:9000/PortalApp/api/v1/some/service/call?apiProxy=LocalhostNode

redirects to the endpoint defined by LocalhostNode (ie, port 8080)...

http://localhost:8080/PortalApp/api/v1/some/service/call?apiProxy=LocalhostNode

Setup

In your Gruntfile.js

var apiProxy = require('grunt-json-proxy').initialize({
    // A 'node' is referenced by name in the 'proxy.forward' section below, instead of a URL.
    nodes: {
        ihportal: {
            // Each endpoint is listed here as in key: endpoint format.
            'Localhost': 'http://localhost:8080/'
        }
    },

    // If no endpoint name is passed in a http header or url parameter, use this one.
    defaultEndpointName: 'Localhost',

    // Proxy's, as defined by json-proxy, however the value of each 'forward' entry is a 'node' (as defined above) instead of a url.
    proxy: {
        forward: {
            '/PortalApp/': 'ihportal'
        }
    }
});


// Define the configuration for all the tasks
grunt.initConfig({

    // The actual grunt server settings
    connect: {
        options: {
            port: 9000,
            // Change this to '0.0.0.0' to access the server from outside.
            hostname: 'localhost',
            livereload: 35729
        },
        livereload: {
            options: {
                middleware: function (connect) {
                    return [
                        connect.static(appConfig.app),


                        // The apiProxy middleware is place HERE
                        apiProxy


                        ]
                    }
                }
            }
        }
    });

FAQs

Package last updated on 08 May 2015

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