Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsforce/jsforce-ajax-proxy
A proxy server to access Salesforce API from JavaScript apps outside of Salesforce domain.
https://github.com/jsforce/jsforce-ajax-proxy
jsforce salesforce
Last synced: about 1 month ago
JSON representation
A proxy server to access Salesforce API from JavaScript apps outside of Salesforce domain.
- Host: GitHub
- URL: https://github.com/jsforce/jsforce-ajax-proxy
- Owner: jsforce
- License: mit
- Created: 2014-02-01T14:57:17.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-01-05T07:54:51.000Z (12 months ago)
- Last Synced: 2024-04-14T21:15:05.359Z (8 months ago)
- Topics: jsforce, salesforce
- Language: JavaScript
- Size: 40 KB
- Stars: 51
- Watchers: 4
- Forks: 48
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
```javascript
var conn = new jsforce.Connection({
accessToken: '',
instanceUrl: '',
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:
```javascript
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.
```javascript
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.