Merge pull request #215 from pnagurny/feature/web-docs

Add docs for web service
This commit is contained in:
Braydon Fuller 2015-09-10 13:11:32 -04:00
commit 13b5c065f3
2 changed files with 42 additions and 0 deletions

View File

@ -37,6 +37,7 @@ bitcore-node start --daemon
- [Bitcoind](docs/services/bitcoind.md) - Native bindings to Bitcoin Core
- [Database](docs/services/db.md) - The foundation API methods for getting information about blocks and transactions.
- [Address](docs/services/address.md) - Adds additional API methods for querying and subscribing to events with bitcoin addresses.
- [Web](docs/services/web.md) - Creates an express application over which services can expose their web/API content
- [Build & Install](docs/build.md) - How to build and install from source
- [Testing & Development](docs/testing.md) - Developer guide for testing
- [Node](docs/node.md) - Details on the node constructor

41
docs/services/web.md Normal file
View File

@ -0,0 +1,41 @@
# Web Service
The web service creates an express app which can be used by services for setting up web routes for API's, static content, web applications, etc. This allows users to interact with various bitcore node services over one http or https port.
In order for your service to add routes, it must implement the `setupRoutes()` and `getRoutePrefix()` methods.
## Example
```js
MyService.prototype.setupRoutes = function(app, express) {
// Set up routes
app.get('/hello', function(req, res) {
res.send('world');
});
// Serve static content
app.use('/static', express.static(__dirname + '/static'));
};
MyService.prototype.getRoutePrefix = function() {
return 'my-service'
};
```
## Configuring Web Service for HTTPS
You can run the web service over https by editing your bitcore node config, setting https to true and adding httpsOptions:
```json
{
"port": 3001,
"https": true,
"httpsOptions": {
"key": "path-to-private-key",
"cert": "path-to-certificate"
},
"services": [
"web"
]
}
```