Skip to content

Commit

Permalink
Merge branch 'develop' into feature/EV-1155-merchants-setup-admin-app
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq authored Apr 12, 2019
2 parents 0502534 + d52fad8 commit eb75361
Show file tree
Hide file tree
Showing 17 changed files with 7,215 additions and 7,562 deletions.
156 changes: 45 additions & 111 deletions README.md

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions admin/website-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@
"zone.js": "^0.8.29"
},
"devDependencies": {
"@angular-devkit/architect": "^0.13.7",
"@angular-devkit/build-angular": "^0.13.7",
"@angular-devkit/build-webpack": "^0.13.7",
"@angular-devkit/core": "^7.3.7",
"@angular-devkit/schematics": "^7.3.7",
"@angular/cli": "^7.3.7",
"conventional-changelog-cli": "^2.0.12",
"@angular-devkit/build-angular": "^0.13.8",
"@angular-devkit/build-webpack": "^0.13.8",
"@angular-devkit/architect": "^0.13.8",
"@angular-devkit/core": "^7.3.8",
"@angular-devkit/schematics": "^7.3.8",
"@angular/cli": "^7.3.8",
"@angular/compiler-cli": "^7.2.11",
"@angular/language-service": "^7.2.11",
"@babel/core": "^7.4.0",
Expand All @@ -174,10 +175,9 @@
"@types/socket.io-client": "^1.4.32",
"@types/stripe": "^6.25.7",
"@types/uuid": "^3.4.4",
"@types/yargs": "^12.0.9",
"@types/yargs": "^13.0.0",
"babel-loader": "^8.0.5",
"codelyzer": "^4.5.0",
"conventional-changelog-cli": "^2.0.11",
"cross-env": "^5.2.0",
"dotenv": "^6.2.0",
"envalid": "^4.2.2",
Expand Down
2,040 changes: 966 additions & 1,074 deletions admin/website-angular/yarn.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions backend/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@nestjs/testing": "^6.0.2",
"@nestjs/typeorm": "^6.0.0",
"@nestjs/websockets": "^6.0.2",
"swagger-ui-express": "^4.0.2",
"apollo-server-express": "^2.4.8",
"axios": "^0.18.0",
"bcrypt": "^3.0.4",
Expand All @@ -79,6 +78,7 @@
"envalid": "^4.2.2",
"errorhandler": "^1.5.0",
"etag": "^1.8.1",
"event-stream": "3.3.4",
"express": "^4.16.4",
"express-handlebars": "^3.0.2",
"faker": "^4.1.0",
Expand All @@ -99,8 +99,8 @@
"module-alias": "^2.2.0",
"moment": "^2.24.0",
"mongodb": "^3.2.1",
"mongodb-memory-server": "^4.2.1",
"mongoose": "^5.4.19",
"mongodb-memory-server": "^5.0.2",
"mongoose": "^5.5.0",
"morgan": "^1.9.1",
"ms": "^2.1.1",
"node-sass": "^4.11.0",
Expand All @@ -112,6 +112,7 @@
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"passport-url": "^1.0.4",
"pem": "^1.14.2",
"pm2": "^3.4.0",
"redis": "^2.8.0",
"reflect-metadata": "^0.1.13",
Expand All @@ -126,6 +127,7 @@
"source-map-support": "^0.5.11",
"stripe": "^6.28.0",
"subscriptions-transport-ws": "^0.9.16",
"swagger-ui-express": "^4.0.2",
"symbol": "^0.3.1",
"symbol-observable": "^1.2.0",
"typeorm": "^0.2.15",
Expand All @@ -134,8 +136,7 @@
"upath": "^1.1.2",
"uuid": "^3.3.2",
"validator": "^10.11.0",
"ws": "^6.2.0",
"event-stream": "3.3.4"
"ws": "^6.2.0"
},
"devDependencies": {
"@commitlint/cli": "^7.5.2",
Expand Down
18 changes: 18 additions & 0 deletions backend/api/src/graphql/subscriptions/subscription.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@ import { SUBSCRIPTION_SERVER } from './subscription.constants';
export const createSubscriptionProviders = (port: number = 5050) => [
{
provide: SUBSCRIPTION_SERVER,

useFactory: () => {
const server = createServer();

const closeServer = () => {
try {
if (server != null) {
server.close(() => {
process.exit(0);
});
}
} catch (err) {
process.exit(0);
}
};

process
.on('SIGINT', () => closeServer())
.on('SIGTERM', () => closeServer());

return new Promise((resolve) =>
server.listen(port, () => resolve(server))
);
Expand Down
114 changes: 103 additions & 11 deletions backend/api/src/services/services.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ProductsCategory from '@modules/server.common/entities/ProductsCategory';
import User from '@modules/server.common/entities/User';
import Warehouse from '@modules/server.common/entities/Warehouse';
import { ConfigService } from '../config/config.service';
import * as pem from 'pem';

// local IPs
const INTERNAL_IPS = ['127.0.0.1', '::1'];
Expand Down Expand Up @@ -272,7 +273,7 @@ export class ServicesApp {
});
}

private _startExpress() {
private async _startExpress() {
// that's important to see even if logs disabled, do not remove!
console.log('Connected to DB');

Expand All @@ -296,21 +297,40 @@ export class ServicesApp {

this.expressApp.set('view cache', false);

// TODO: this is probably a good place to check if Cert files exists and if not generate them for localhost
this.httpsServer = https.createServer(
{
cert: fs.readFileSync(env.HTTPS_CERT_PATH),
key: fs.readFileSync(env.HTTPS_KEY_PATH)
},
this.expressApp
);
// now we check if Cert files exists and if not generate them for localhost
const httpsCertPath = env.HTTPS_CERT_PATH;
const httpsKeyPath = env.HTTPS_KEY_PATH;

const hasHttpsCert = fs.existsSync(httpsCertPath);
const hasHttpsKey = fs.existsSync(httpsKeyPath);

let hasDefaultHttpsCert = false;

if (!hasHttpsCert || !hasHttpsKey) {
hasDefaultHttpsCert = await this._getCertificates(
httpsCertPath,
httpsKeyPath
);
}

if ((hasHttpsCert && hasHttpsKey) || hasDefaultHttpsCert) {
this.httpsServer = https.createServer(
{
cert: fs.readFileSync(httpsCertPath),
key: fs.readFileSync(httpsKeyPath)
},
this.expressApp
);
}

this.httpServer = http.createServer(this.expressApp);

// TODO: add to settings file
// set connections timeouts to 30 minutes (for long running requests)
const timeout = 30 * 60 * 1000;
this.httpsServer.setTimeout(timeout);
if (this.httpsServer) {
this.httpsServer.setTimeout(timeout);
}
this.httpServer.setTimeout(timeout);

this.expressApp.set('httpsPort', env.HTTPSPORT);
Expand Down Expand Up @@ -406,7 +426,7 @@ export class ServicesApp {
'Express server prepare to listen'
);

if (httpsPort && httpsPort > 0) {
if (httpsPort && httpsPort > 0 && this.httpsServer) {
// app listen on https
this.httpsServer.listen(httpsPort, () => {
this.log.info(
Expand All @@ -417,6 +437,10 @@ export class ServicesApp {
`Express https server listening on port ${httpsPort}`
);
});
} else {
this.log.warn(
`No SSL Certificate exists, HTTPS endpoint will be disabled`
);
}

if (httpPort && httpPort > 0) {
Expand All @@ -433,6 +457,74 @@ export class ServicesApp {
}
}

private async _getCertificates(
httpsCertPath: string,
httpsKeyPath: string
) {
try {
this.log.info('Generating SSL Certificates for HTTPS');

let { success } = await this._createCertificateAsync(
httpsCertPath,
httpsKeyPath
);

this.log.info('Certificates were generated');

return success;
} catch (error) {
this.log.warn(
`Certificates were not generated due to error: ${error.message}`
);

return false;
}
}

private _createCertificateAsync(
httpsCertPath: string,
httpsKeyPath: string
): Promise<{ success: boolean }> {
return new Promise((resolve, reject) => {
try {
pem.createCertificate(
{
days: 365,
selfSigned: true
},
(err, keys) => {
if (err) {
reject({ success: false, message: err.message });
return;
}

const httpsCertDirPath = path.dirname(httpsCertPath);
const httpsKeyDirPath = path.dirname(httpsKeyPath);

if (!fs.existsSync(httpsCertDirPath)) {
fs.mkdirSync(httpsCertDirPath, {
recursive: true
});
}

if (!fs.existsSync(httpsKeyDirPath)) {
fs.mkdirSync(httpsKeyDirPath, {
recursive: true
});
}

fs.writeFileSync(httpsCertPath, keys.certificate);
fs.writeFileSync(httpsKeyPath, keys.serviceKey);

resolve({ success: true });
}
);
} catch (err) {
reject({ success: false, message: err.message });
}
});
}

private _startSocketIO() {
const ioHttps = socketIO(this.httpsServer);
const ioHttp = socketIO(this.httpServer);
Expand Down
Loading

0 comments on commit eb75361

Please sign in to comment.