From 6d514febf36a435cd7325f29aad72b691a284452 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Thu, 10 Sep 2015 11:56:16 -0400 Subject: [PATCH] document the web service --- README.md | 1 + docs/services/web.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 docs/services/web.md diff --git a/README.md b/README.md index 5f8f6225..b8bf6a30 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/services/web.md b/docs/services/web.md new file mode 100644 index 00000000..8f9bea8a --- /dev/null +++ b/docs/services/web.md @@ -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" + ] +} +``` \ No newline at end of file