-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changing CLI args + adding debug mode
- Loading branch information
1 parent
0a505ca
commit 584fa05
Showing
6 changed files
with
116 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
node_modules | ||
.DS_Store | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,68 @@ | ||
# force-server | ||
# ForceServer | ||
|
||
force-server is a simple development server for Force.com. It provides two main features: | ||
ForceServer is a simple development server aimed at providing a simple and integrated developer experience when building applications that use Salesforce OAuth and REST services. ForceServer provides two main features: | ||
|
||
- **A Proxy Server**: allows you to avoid cross domain policy issues when making REST API calls to Salesforce | ||
- **A Local Web Server**: allows you to avoid cross domain policy issues when loading application resources using XMLHTTPRequest (templates, etc.) | ||
- **A Proxy Server** to avoid cross-domain policy issues when invoking Salesforce REST services. (The Chatter API supports CORS, but other APIs don’t yet) | ||
- **A Local Web Server** to (1) serve the OAuth callback URL defined in your Connected App, and (2) serve the whole app during development and avoid cross-domain policy issues when loading files (for example, templates) from the local file system. | ||
|
||
There are different options to use force-server: | ||
## Installing ForceServer | ||
|
||
## Option 1: Install as a CLI | ||
|
||
1. Install the force-server CLI | ||
Open a command prompt and type: | ||
|
||
``` | ||
npm install -g force-server | ||
``` | ||
|
||
or (Unix-based systems) | ||
|
||
``` | ||
sudo npm install -g force-server | ||
``` | ||
|
||
1. Start the server | ||
|
||
``` | ||
force-server [webRoot] [port] | ||
``` | ||
|
||
- **webRoot**: path to the web root directory relative to the current directory. The default is the current directory. | ||
- **port**: server port number. The default is 5000. | ||
|
||
Examples: | ||
|
||
To start force-server on port 5000 (default) and serve files in the current directory: | ||
``` | ||
force-server | ||
``` | ||
|
||
To start force-server on port 5000 (default) and serve files in the **www** directory (relative to the current directory): | ||
``` | ||
force-server www | ||
``` | ||
|
||
To start force-server on port 8000 and serve files in the **www** directory (relative to the current directory): | ||
``` | ||
force-server www 8000 | ||
``` | ||
|
||
## Option 2: Install a local version | ||
|
||
1. Clone this repository | ||
|
||
``` | ||
git clone https://github.com/ccoenraets/force-server | ||
``` | ||
|
||
1. Navigate to the force-server directory | ||
|
||
``` | ||
cd force-server | ||
``` | ||
|
||
1. Install the server dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
1. Start the server | ||
|
||
``` | ||
node server [webRoot] [port] | ||
sudo npm install -g force-server | ||
``` | ||
|
||
## Sample App | ||
|
||
## Option 3: Deploy to Heroku | ||
|
||
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) | ||
Create a file named index.html anywhere on you file system: | ||
|
||
Because force-server is itself CORS-enabled, your application and the proxy don't have to be hosted on the same | ||
domain. | ||
|
||
## Proxy Server Usage | ||
|
||
When making an API call using JavaScript (using XMLHTTPRequest, $.ajax, etc): | ||
|
||
1. Substitute the actual service URL with the Proxy URL | ||
|
||
1. Set the request method, query parameters, and body as usual | ||
|
||
1. Set the actual service URL in a header named 'Target-Endpoint' | ||
|
||
1. Send the request as usual | ||
``` | ||
[html] | ||
<html> | ||
<body> | ||
<ul id="list"></ul> | ||
<script src="http://ccoenraets.github.io/forcejs/force.js"></script> | ||
<script> | ||
force.login(function() { | ||
force.query('select id, Name from contact LIMIT 50', function (response) { | ||
var str = ''; | ||
for (var i = 0; i < response.records.length; i++) { | ||
str += '<li>' + response.records[i].Name + '</li>'; | ||
} | ||
document.getElementById('list').innerHTML = str; | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
[/html] | ||
``` | ||
|
||
These steps are automated when using the [ForceJS](https://github.com/ccoenraets/forcejs) REST Library | ||
## Run the Server | ||
|
||
## Uninstalling the CLI | ||
Navigate to the directory where you created index.html, and type: | ||
|
||
To uninstall the CLI: | ||
|
||
``` | ||
npm -g rm force-server | ||
``` | ||
force-server | ||
``` | ||
|
||
This command will start the server on port 8200, and automatically load your app (http://localhost:8200) in a browser window. You'll see the Salesforce login window, and the list of contacts will appear after you log in. | ||
|
||
or | ||
You can change the port number and the web root. Type the following command for more info: | ||
|
||
``` | ||
sudo npm -g rm force-server | ||
force-server --help | ||
``` | ||
|
||
## Related Project | ||
## Code Highlights | ||
|
||
[ForceJS](https://github.com/ccoenraets/forcejs) is a REST Library for Force.com that works together with force-server to provide an integrated devlopment experience when building apps that connect to Salesforce using REST services. | ||
1. The sample application above uses the <a href="">ForceJS</a> library. ForceJS and ForceServer are built to work closely together and provide an integrated developer experience. | ||
1. ForceJS uses a default connected app: No need to create a connected app to start development. You should however create your own connected app for production use. | ||
1. ForceServer automatically serves the OAuth callback URL: No need to create a callback HTML page during development. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
hello root | ||
Hello Root! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<html> | ||
<body> | ||
<script> | ||
if (window.opener.force && window.opener.force.oauthCallback) { | ||
window.opener.force.oauthCallback(window.location.href); | ||
} else if (window.opener.oauthCallback) { | ||
window.opener.oauthCallback(window.location.href); | ||
} | ||
window.close(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
{ | ||
"name": "force-server", | ||
"version": "0.0.5", | ||
"description": "Development server for Force.com", | ||
"bin": { | ||
"force-server": "./bin/force-server.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ccoenraets/force-server.git" | ||
}, | ||
"keywords": [ | ||
"salesforce", | ||
"force.com", | ||
"proxy", | ||
"cors", | ||
"webserver" | ||
], | ||
"author": "Christophe Coenraets <ccoenraets@gmail.com> (http://coenraets.org/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ccoenraets/force-server/issues" | ||
}, | ||
"homepage": "https://github.com/ccoenraets/force-server", | ||
"dependencies": { | ||
"express": "~4.9.8", | ||
"body-parser": "~1.9.0", | ||
"request": "~2.45.0" | ||
} | ||
} | ||
"name": "force-server", | ||
"version": "0.0.6", | ||
"description": "Development server for Force.com", | ||
"bin": { | ||
"force-server": "./bin/force-server.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ccoenraets/force-server.git" | ||
}, | ||
"keywords": [ | ||
"salesforce", | ||
"force.com", | ||
"proxy", | ||
"cors", | ||
"webserver", | ||
"forcejs" | ||
], | ||
"author": "Christophe Coenraets <ccoenraets@gmail.com> (http://coenraets.org/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ccoenraets/force-server/issues" | ||
}, | ||
"homepage": "https://github.com/ccoenraets/force-server", | ||
"dependencies": { | ||
"body-parser": "~1.9.0", | ||
"express": "~4.9.8", | ||
"minimist": "^1.1.0", | ||
"open": "0.0.5", | ||
"request": "~2.45.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters