Commit 5081ccdc authored by Evgeniy Zaitsev's avatar Evgeniy Zaitsev
Browse files

v0.0.5

parent 35173e57
'use strict'; 'use strict';
const fs = require('fs');
const http = require('http');
const https = require('https');
const koa = require('koa'); const koa = require('koa');
const validate = require('koa-validate'); const validate = require('koa-validate');
const sslify = require('koa-sslify');
const Promise = require('bluebird'); const Promise = require('bluebird');
const mysql = require('mysql'); const mysql = require('mysql');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
...@@ -28,6 +32,10 @@ class SDK { ...@@ -28,6 +32,10 @@ class SDK {
this.server.use(require('koa-bodyparser')()); this.server.use(require('koa-bodyparser')());
this.server.use(router.routes()); this.server.use(router.routes());
if (this.config.httpsPort) {
this.server.use(sslify());
}
this.server.env = this.config.env || 'production'; this.server.env = this.config.env || 'production';
this.server.context.tablesNames = tablesNames; this.server.context.tablesNames = tablesNames;
...@@ -78,9 +86,29 @@ class SDK { ...@@ -78,9 +86,29 @@ class SDK {
yield * connectToMySql.call(this.server.context); yield * connectToMySql.call(this.server.context);
yield * createTables.call(this.server.context); yield * createTables.call(this.server.context);
this.server.listen(this.config.httpPort); this._createHttp();
this._createHttps();
}
_createHttp() {
http.createServer(this.server.callback()).listen(this.config.httpPort);
this.server.context.logger.log(__filename, `HTTP is listening on port: ${this.config.httpPort}`);
}
_createHttps() {
if (!this.config.httpsPort) {
return;
}
const options = {
key: fs.readFileSync(this.config.ssl.keyFileName),
cert: fs.readFileSync(this.config.ssl.certFileName)
};
https.createServer(options, this.server.callback()).listen(this.config.httpsPort);
logger.log(__filename, `App is listening on port: ${this.config.httpPort}`); this.server.context.logger.log(__filename, `HTTPS is listening on port: ${this.config.httpsPort}`);
} }
_fetchPrivateFeed(feedName, feedEndpoint, feedUUID) { _fetchPrivateFeed(feedName, feedEndpoint, feedUUID) {
......
{ {
"name": "service-sdk", "name": "service-sdk",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"description": "Service SDK for LViS", "description": "Service SDK for LViS",
"keywords": [], "keywords": [],
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"koa-bodyparser": "^2.2.0", "koa-bodyparser": "^2.2.0",
"koa-json": "^1.1.3", "koa-json": "^1.1.3",
"koa-router": "^5.4.0", "koa-router": "^5.4.0",
"koa-sslify": "^1.1.0",
"koa-validate": "^1.0.7", "koa-validate": "^1.0.7",
"mysql": "^2.11.1", "mysql": "^2.11.1",
"node-fetch": "^1.6.3", "node-fetch": "^1.6.3",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment