-
Notifications
You must be signed in to change notification settings - Fork 28
Espresso server
Status: 16.01.2012 - work in progress
The Espresso server
tool builds and attaches the application to the build-in Espresso server, for the testing. This servers covers also the handling of proxy requests to test remote service calls. Just like in the Espresso build tool, the application is build and bundled, but nit written into the local file system. Instead the application is stored in the servers local memory. But in principle, the same steps are realized.
- -m, --manifest Start the server in manifest mode. Enable generation of cache.manifest Default: false
- -c, --config=CONFIG Specify a custom config
- -d, --directory=DIRECTORY Specify a custom project directory Default: $PWD
- -p, --port=PORT Specify a custom port Default: 8000
- -h, --help Show this help for command server Default: false
To start the server, type:
path/to/Espresso/bin/espresso.js server
, when inside the the applications folder.
Currently (see status) the server takes no additional arguments. to work with Espresso server, no execution of Espresso build is needed, just run espresso server
.
If the build was successfully, Espresso server - responds with: Server running at http://127.0.0.1:8000/<name of the application>
.
Copy & Paste the url into your web browser, (Safari or Chrome are recommended).
Since Espresso server is meant as server testing server for development, it covers the proxying of requests to web services, hosted either on your or an some third party servers. To define a proxy, open the config.json
, located in your projects root folder - see also config.json :
{
"name" : "Twitter",
"version": "v0.0.1",
"proxies":[
{"host":"your.remoteService.com",
"proxyAlias": "remoteService",
"requestMethod": "GET",
"hostPort": "80"}
]
}
Each proxy entry takes 4 properties:
-
host
= the url to the remote service, no http:// as prefix is needed. -
proxyAlias
= the proxy alias name, used in the applications code. -
requestMethod
= the request method for the proxy call, default is "GET". -
hostPort
= the port of the remote service, default is "80"
If you making a simple search request to the twitter search service, the remote url would be:
http://search.twitter.com/search.json?q=NewYork&rpp=10'
Here, the results are the first 10 tweets containing the string "NewYork".
The host
will be search.twitter.com
, this is the part of the url that should be proxied.
The proxy
can be twitter
, so the application is using the term twitter
instead of search.twitter.com
, to request some tweeds from the twitter service.
In the JavaScript code you´ll need to write: /twitter/search.json?q=NewYork&rpp=10'
** Please note:** to have a leading /
before the proxy alias name, when using within the JavaScript code.
proxy entry
...
"proxies":[
{"host":"search.twitter.com",
"proxyAlias": "twitter",
"requestMethod": "GET",
"hostPort": "80"}
]
...
M.Request
M.Request.init({
url: '/twitter/search.json?q=' + searchString + '&rpp=10',
isJSON: YES,
beforeSend: function(req) {
//...
},
onSuccess: function(data){
// on success handling here
},
onError: function(err){
// error handling here
}
}).send();