microphone-express
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -27,5 +27,15 @@ 'use strict'; | ||
/** | ||
* | ||
*/ | ||
var ExpressProvider = function (_FrameworkProvider) { | ||
_inherits(ExpressProvider, _FrameworkProvider); | ||
/** | ||
* | ||
* @param configuration | ||
* @param logger | ||
*/ | ||
function ExpressProvider(configuration, logger) { | ||
@@ -41,2 +51,10 @@ _classCallCheck(this, ExpressProvider); | ||
/** | ||
* | ||
* @param server | ||
* @param serviceName | ||
* @param version | ||
* @returns {Promise} | ||
*/ | ||
_createClass(ExpressProvider, [{ | ||
@@ -51,9 +69,37 @@ key: 'start', | ||
return new Promise(function (resolve, reject) { | ||
var serverInstance = app.listen(_this2._configuration.getPort() || 3000, function (err) { | ||
if (err) return reject(err); | ||
return new Promise(function _callee(resolve, reject) { | ||
var port, uri, serverInstance; | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return regeneratorRuntime.awrap(_this2._configuration.getPort()); | ||
_this2._logger.info('Example app listening on port ' + (_this2._configuration.getPort() || 3000) + '!'); | ||
resolve(serverInstance); | ||
}); | ||
case 2: | ||
_context.t0 = _context.sent; | ||
if (_context.t0) { | ||
_context.next = 5; | ||
break; | ||
} | ||
_context.t0 = 3000; | ||
case 5: | ||
port = _context.t0; | ||
uri = 'http://localhost:' + port; | ||
serverInstance = app.listen(port, function (err) { | ||
if (err) return reject(err); | ||
_this2._logger.info('Example app listening on port ' + port + '!'); | ||
resolve({ serverInstance: serverInstance, uri: uri }); | ||
}); | ||
case 8: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, null, _this2); | ||
}); | ||
@@ -60,0 +106,0 @@ } |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.ExpressProvider = undefined; | ||
@@ -14,2 +13,2 @@ var _expressProvider = require('./express-provider'); | ||
exports.ExpressProvider = _expressProvider2.default; | ||
exports.default = _expressProvider2.default; |
@@ -18,5 +18,4 @@ 'use strict'; | ||
key: 'respond', | ||
value: function respond(req, res, next) { | ||
value: function respond(req, res) { | ||
res.status(200).send('ok'); | ||
next(); | ||
} | ||
@@ -23,0 +22,0 @@ }]); |
{ | ||
"name": "microphone-express", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Express.js provider for microphone.js Microservice framework", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
"express": "^4.13.4", | ||
"microphone-core": "^1.0.2" | ||
"microphone-core": "^1.1.0" | ||
}, | ||
@@ -34,2 +34,5 @@ "devDependencies": { | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-plugin-syntax-async-functions": "^6.3.13", | ||
"babel-plugin-transform-regenerator": "^6.4.4", | ||
"babel-polyfill": "^6.3.14", | ||
"chai": "^3.4.1", | ||
@@ -36,0 +39,0 @@ "eslint": "^1.10.3", |
@@ -6,1 +6,46 @@ # microphone-express | ||
[![Build Status](https://travis-ci.org/microphonejs/microphone-express.svg?branch=master)](https://travis-ci.org/microphonejs/microphone-express) [![Coverage Status](https://coveralls.io/repos/github/microphonejs/microphone-express/badge.svg?branch=master)](https://coveralls.io/github/microphonejs/microphone-express?branch=master) | ||
Preview | ||
================== | ||
**Sample code using `Consul`** | ||
```js | ||
import {Cluster, GuidGenerator, FrameworkProvider, Configuration, Logger} from 'microphone-core'; | ||
import ConsulProvider from 'microphone-consul'; | ||
import ExpressProvider from 'microphone-express'; | ||
import express from 'express' | ||
async function main() { | ||
try { | ||
let server = express(); | ||
let customers = new CustomersController(); | ||
server.get('/customers', customers.index); | ||
let logger = new Logger(); | ||
let configuration = new Configuration(); | ||
let clusterProvider = new ConsulProvider(null, logger); | ||
let frameworkProvider = new ExpressProvider(configuration, logger); | ||
let guidGenerator = new GuidGenerator(); | ||
let cluster = new Cluster(clusterProvider, frameworkProvider, guidGenerator); | ||
await cluster.bootstrap(server, "customers", "v1"); | ||
console.log("STARTED"); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
``` | ||
**Api Controller** | ||
```js | ||
class CustomersController { | ||
index(req, res) { | ||
res.send({ | ||
customerName: "Test customer", | ||
customerId: 666 | ||
}); | ||
} | ||
} | ||
``` |
@@ -1,3 +0,1 @@ | ||
import "babel-polyfill"; | ||
import chai from "chai"; | ||
@@ -7,3 +5,3 @@ import sinon from "sinon"; | ||
import request from 'request'; | ||
import {ExpressProvider} from "../src/index"; | ||
import ExpressProvider from "../src/index"; | ||
@@ -51,14 +49,14 @@ import express from 'express'; | ||
let app = express(); | ||
let server = express(); | ||
await startTest(app, done); | ||
await startTest(server, done); | ||
}); | ||
async function startTest(server, done) { | ||
let port = 8087, statusResponse = 'ok'; | ||
let port = 3001, statusResponse = 'ok'; | ||
configurationMock.expects("getPort").returns(port).twice(); | ||
configurationMock.expects("getPort").returns(port).once(); | ||
loggerMock.expects("info").withArgs(`Example app listening on port ${port}!`).once(); | ||
let serverInstance = await expressProvider.start(server, "test-svc", "v1"); | ||
let result = await expressProvider.start(server, "test-svc", "v1"); | ||
@@ -71,3 +69,3 @@ request(`http://localhost:${port}/status`, (error, response, body)=> { | ||
serverInstance.close(); | ||
result.serverInstance.close(); | ||
done(); | ||
@@ -74,0 +72,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44631
158
50
13
20
Updatedmicrophone-core@^1.1.0