Giter VIP home page Giter VIP logo

jsforce-ajax-proxy's Introduction

JSforce AJAX Proxy

A proxy server to access Salesforce API from JSforce JavaScript apps served outside of Salesforce.

As the same origin policy restricts communication to the Salesforce API from outer domain, you should serve cross-domain proxy server when you build a app using JSforce outside of Salesforce.

As Salesforce REST API supports CORS (Cross-Origin Resource Sharing) access, this proxy is not always required when you are using only REST API and you can change security setting in your connecting organization. This proxy is still useful because you can access not only REST APIs but also SOAP-based APIs from outer domain.

Usage

Start proxy server in your server environment which can run Node.js app (Heroku is the one you might choose).

Install required packages :

$ npm install

Run proxy server :

$ npm start

When you use JSforce in your JavaScript app, set proxyUrl when creating Connection instance.

var conn = jsforce.Connection({
  accessToken: '<access_token>',
  instanceUrl: '<instance_url>',
  proxyUrl: 'https://your-ajax-proxy-service.herokuapp.com/proxy/'
});

conn.query('SELECT Id, Name FROM Account', function(err, res) {
  // ...
});

Using as Middleware

Ajax proxy is not only provided in standalone server but also works as connect middleware. You can include the proxy functionality in your express.js app.

First install jsforce-ajax-proxy in your app project:

$ npm install jsforce-ajax-proxy --save

Then include the middleware under certain path:

var express = require('express');
var jsforceAjaxProxy = require('jsforce-ajax-proxy');
var app = express();

app.all('/proxy/?*', jsforceAjaxProxy());

If you want to accept http request from other origin, set enableCORS option to true.

app.all('/proxy/?*', jsforceAjaxProxy({ enableCORS: true });

Note

You don't have to use this app when you are building a JSforce app in Visualforce, because it works in the same domain as Salesforce API.

jsforce-ajax-proxy's People

Contributors

stomita avatar cwarden avatar

Watchers

James Cloos avatar Robert Baindourov 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.