Skip to content

Commit

Permalink
BE-769 Initial migration (#175)
Browse files Browse the repository at this point in the history
* BE-769 Initial migration from JS to TS

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>

* BE-769 Exclude files related to e2e test

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia authored Sep 14, 2020
1 parent 59fa173 commit 7eff791
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 274 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
"userlist",
"unregister",
"userdataservice",
"parens"
"parens",
"npm"
],
"skipIfMatch": ["http://[^s]*", "[a-z]scc"],
"skipWordIfMatch": ["^foobar.*$"],
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,16 @@ $ npm run build
}
```

* `./start.sh`
* `npm start`
* It will have the backend and GUI service up

* `./stop.sh`
* `npm run app-stop`
* It will stop the node server

**Note:** If Hyperledger Fabric network is deployed on other machine, please define the following environment variable

```
$ DISCOVERY_AS_LOCALHOST=false ./start.sh
$ DISCOVERY_AS_LOCALHOST=false npm start
```
### Run Standalone in Different Location
Expand Down
8 changes: 6 additions & 2 deletions app/Explorer.js → app/Explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const swaggerUi = require('swagger-ui-express');
const compression = require('compression');
const passport = require('passport');
const RateLimit = require('express-rate-limit');
const PlatformBuilder = require('./platform/PlatformBuilder');
import {PlatformBuilder } from './platform/PlatformBuilder';
const explorerconfig = require('./explorerconfig.json');
const PersistenceFactory = require('./persistence/PersistenceFactory');
const ExplorerError = require('./common/ExplorerError');
Expand All @@ -32,12 +32,16 @@ const explorer_error = require('./common/ExplorerMessage').explorer.error;
* @class Explorer
*/
class Explorer {

app = Express();
persistence : any;
platforms : any[];

/**
* Creates an instance of Explorer.
* @memberof Explorer
*/
constructor() {
this.app = new Express();

// set up rate limiter: maximum of 1000 requests per minute

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ExplorerError = require('../common/ExplorerError');
*
* @class PlatformBuilder
*/
class PlatformBuilder {
export class PlatformBuilder {
/**
*
*
Expand All @@ -31,5 +31,3 @@ class PlatformBuilder {
throw new ExplorerError(explorer_error.ERROR_1004, pltfrm);
}
}

module.exports = PlatformBuilder;
6 changes: 3 additions & 3 deletions app/platform/fabric/FabricConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class FabricConfig {

if (organization.signedCert.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', organization.signedCert.path),
path.resolve(__dirname, '../../../..', organization.signedCert.path),
'utf8'
);
}
Expand All @@ -268,7 +268,7 @@ class FabricConfig {

if (organization.adminPrivateKey.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', organization.adminPrivateKey.path),
path.resolve(__dirname, '../../../..', organization.adminPrivateKey.path),
'utf8'
);
}
Expand All @@ -293,7 +293,7 @@ class FabricConfig {

if (tlsCACerts.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../..', tlsCACerts.path),
path.resolve(__dirname, '../../../..', tlsCACerts.path),
'utf8'
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/platform/fabric/e2e-test/specs/runexplorer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fi

# export LOG_LEVEL_CONSOLE=debug
export EXPLORER_SYNC_BLOCKSYNCTIME_SEC=5
./start.sh
npm start
echo "#### Starting Explorer process ..."

rc=1
Expand Down
2 changes: 1 addition & 1 deletion app/platform/fabric/e2e-test/specs/stopexplorer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ done

pushd ${ROOTPATH}

./stop.sh
npm run app-stop
if [ $CLEANUP -eq 1 ]; then
docker-compose -f ./app/platform/fabric/e2e-test/docker-compose.yaml down -v
rm -rf wallet/ logs/
Expand Down
4 changes: 2 additions & 2 deletions client/e2e-test/specs/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('GUI e2e test', () => {

process.env.LOG_LEVEL_CONSOLE = 'debug';
process.env.EXPLORER_SYNC_BLOCKSYNCTIME_SEC = '10';
child = spawn('./start.sh', [], {
child = spawn('npm', ['start'], {
cwd: rootdir,
env: process.env,
shell: true
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('GUI e2e test', () => {

process.chdir(rootdir);

child = spawnSync('./stop.sh', [], {
child = spawnSync('npm', ['run', 'app-stop'], {
cwd: rootdir,
env: process.env,
shell: true
Expand Down
6 changes: 3 additions & 3 deletions main.js → main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const http = require('http');
const https = require('https');
const fs = require('fs');
const url = require('url');
const WebSocket = require('ws');
import * as WebSocket from 'ws';
const appconfig = require('./appconfig.json');
const helper = require('./app/common/helper');

Expand Down Expand Up @@ -114,7 +114,7 @@ async function startExplorer() {
}
const broadcaster = new Broadcaster(server);
await explorer.initialize(broadcaster);
explorer.getApp().use(express.static(path.join(__dirname, 'client/build')));
explorer.getApp().use(express.static(path.join(__dirname, '..', 'client/build')));

// ============= start server =======================
server.listen(port, () => {
Expand Down Expand Up @@ -159,7 +159,7 @@ const shutDown = function(exitCode) {
setTimeout(() => connections.forEach(curr => curr.destroy()), 5000);
};

process.on('unhandledRejection', up => {
process.on('unhandledRejection', (up: Error) => {
logger.error(
'<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>'
);
Expand Down
Loading

0 comments on commit 7eff791

Please sign in to comment.