Skip to content

Commit

Permalink
Fix tsconfig.json for backward compatibility for docker env (#185)
Browse files Browse the repository at this point in the history
* BE-831 Transcode to typescript

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

* BE-831 Fix directory structure for keeping compatibility

For container environment, reverted root path for app from dist/ to app/.

Signed-off-by: Atsushi Neki <atsushin@fast.au.fujitsu.com>
  • Loading branch information
nekia authored Sep 27, 2020
1 parent 65b5001 commit a105280
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ ENV DATABASE_PORT 5432
ENV DATABASE_NAME fabricexplorer
ENV DATABASE_USERNAME hppoc
ENV DATABASE_PASSWD password
ENV EXPLORER_APP_ROOT app

ENV DEFAULT_WORKDIR /opt
ENV EXPLORER_APP_PATH $DEFAULT_WORKDIR/explorer

WORKDIR $EXPLORER_APP_PATH

COPY . .
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/dist ./dist/
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/dist ./app/
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/client/build ./client/build/
COPY --from=BUILD_IMAGE $EXPLORER_APP_PATH/node_modules ./node_modules/

Expand Down
7 changes: 4 additions & 3 deletions app/Explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import {platformroutes} from './rest/platformroutes';
import {adminroutes} from './platform/fabric/rest/adminroutes';
import {explorerConst} from './common/ExplorerConst'
import {explorerError} from './common/ExplorerMessage'
import authCheckMiddleware from './middleware/auth-check';
import swaggerDocument from '../swagger.json';
import {authCheckMiddleware} from './middleware/auth-check';
import swaggerDocument from './swagger.json';
import {ExplorerError} from './common/ExplorerError';
const localLoginStrategy = require('./passport/local-login');
import {localLoginStrategy} from './passport/local-login';

/**
*
*
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions main.ts → app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Created by shouhewu on 6/8/17.
*
*/
import {helper} from './app/common/helper';
import {helper} from './common/helper';

import express from 'express';
import helmet from 'helmet';
Expand All @@ -21,8 +21,8 @@ import appconfig from './appconfig.json';

const logger = helper.getLogger('main');

import {Explorer} from './app/Explorer';
import {ExplorerError} from './app/common/ExplorerError';
import {Explorer} from './Explorer';
import {ExplorerError} from './common/ExplorerError';

const sslEnabled = process.env.SSL_ENABLED || appconfig.sslEnabled;
const sslCertsPath = process.env.SSL_CERTS_PATH || appconfig.sslCertsPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config = require('../explorerconfig.json');
/**
* The Auth Checker middleware function.
*/
module.exports = (req, res, next) => {
export const authCheckMiddleware = (req, res, next) => {
if (!req.headers.authorization) {
return res.status(401).end();
}
Expand Down
File renamed without changes.
10 changes: 2 additions & 8 deletions app/passport/local-login.js → app/passport/local-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = require('../explorerconfig.json');
// @ts-check
const jwtSignAsync = promisify(jwt.sign);

const strategy = function(platform) {
export const localLoginStrategy = function(platform) {
const proxy = platform.getProxy();
return new PassportLocalStrategy(
{
Expand Down Expand Up @@ -47,15 +47,9 @@ const strategy = function(platform) {
// @ts-check
const data = {
message: 'logged in',
name: userData.user,
network: userData.network
name: userData.user
};
return done(null, token, data);
}
);
};

/**
* Return the Passport Local Strategy object.
*/
module.exports = strategy;
1 change: 0 additions & 1 deletion app/persistence/PersistenceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class PersistenceFactory {
* @memberof PersistenceFactory
*/
static async create(db: string, dbconfig: any) {
console.log("check",explorerConst.PERSISTENCE_POSTGRESQL)
if (db === explorerConst.PERSISTENCE_POSTGRESQL) {
// Avoid to load all db Persist module
const PostgreSQL = require('./postgreSQL/Persist');
Expand Down
6 changes: 3 additions & 3 deletions app/platform/fabric/FabricConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export 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 @@ -272,7 +272,7 @@ export 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 @@ -297,7 +297,7 @@ export class FabricConfig {

if (tlsCACerts.path !== undefined) {
return fs.readFileSync(
path.resolve(__dirname, '../../../..', tlsCACerts.path),
path.resolve(__dirname, '../../..', tlsCACerts.path),
'utf8'
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/platform/fabric/sync/SyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ export class SyncServices {
const notify = {
notify_type: fabric_const.NOTITY_TYPE_NEWCHANNEL,
network_id,
chName
channel_name: chName
};

_self.platform.send(notify);
Expand All @@ -475,7 +475,7 @@ export class SyncServices {
const notify = {
notify_type: fabric_const.NOTITY_TYPE_UPDATECHANNEL,
network_id,
chName
channel_name: chName
};

_self.platform.send(notify);
Expand Down Expand Up @@ -617,7 +617,7 @@ export class SyncServices {
const notify = {
notify_type: fabric_const.NOTITY_TYPE_CHAINCODE,
network_id,
chName
channel_name: chName
};

_self.platform.send(notify);
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions sync.js → app/sync.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import { helper } from './app/common/helper';
import { helper } from './common/helper';

import { ExplorerError } from './app/common/ExplorerError';
import { ExplorerError } from './common/ExplorerError';

import { Synchronizer } from './app/Synchronizer';
import { Synchronizer } from './Synchronizer';

const logger = helper.getLogger('Sync');

Expand Down Expand Up @@ -49,7 +49,7 @@ const shutDown = function() {
}, 2000);
};

process.on('unhandledRejection', up => {
process.on('unhandledRejection', (up : {message : string}) => {
logger.error(
'<<<<<<<<<<<<<<<<<<<<<<<<<< Synchronizer Error >>>>>>>>>>>>>>>>>>>>>'
);
Expand Down
2 changes: 1 addition & 1 deletion app/sync/listener/ForkListenerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ForkListenerHandler {
async initialize(args) {
const _self = this;

this.syncProcessor = fork(path.resolve(__dirname, '../../../sync.js'), args);
this.syncProcessor = fork(path.resolve(__dirname, '../../sync.js'), args);

this.syncProcessor.on('message', msg => {
_self.platform.getProxy().processSyncMessage(msg);
Expand Down
4 changes: 2 additions & 2 deletions app/test/currentchannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const chai = require('chai');

const should = chai.should();
const { spy, stub } = require('sinon');
const config = require('../../app/platform/fabric/config');
const appconfig = require('../../appconfig.json');
const config = require('../platform/fabric/config');
const appconfig = require('../appconfig.json');

const host = process.env.HOST || appconfig.host;
const port = process.env.PORT || appconfig.port;
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ services:
- LOG_CONSOLE_STDOUT=true
- DISCOVERY_AS_LOCALHOST=false
volumes:
- ./examples/net1/config.json:/opt/explorer/dist/app/platform/fabric/config.json
- ./examples/net1/connection-profile:/opt/explorer/dist/app/platform/fabric/connection-profile
- ./examples/net1/config.json:/opt/explorer/app/platform/fabric/config.json
- ./examples/net1/connection-profile:/opt/explorer/app/platform/fabric/connection-profile
- ./examples/net1/crypto:/tmp/crypto
- walletstore:/opt/wallet
ports:
Expand Down
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"fabric nodesdk"
],
"dependencies": {
"@types/pg": "^7.14.5",
"@types/sequelize": "^4.28.9",
"@types/ws": "^7.2.6",
"ajv": "^5.5.2",
"app-root-path": "^2.0.1",
"asn1.js": "^5.0.1",
Expand Down Expand Up @@ -59,8 +56,11 @@
"@types/express": "^4.17.8",
"@types/fs-extra": "^9.0.1",
"@types/log4js": "^2.3.5",
"@types/passport": "^1.0.4",
"@types/node": "^14.10.0",
"@types/passport": "^1.0.4",
"@types/pg": "^7.14.5",
"@types/sequelize": "^4.28.9",
"@types/ws": "^7.2.6",
"cross-env": "^5.2.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
Expand Down
4 changes: 3 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export LOG_LEVEL_CONSOLE=${LOG_LEVEL_CONSOLE:-info}
export LOG_CONSOLE_STDOUT=${LOG_CONSOLE_STDOUT:-false}

export DISCOVERY_AS_LOCALHOST=${DISCOVERY_AS_LOCALHOST:-true}
node dist/main.js name - hyperledger-explorer &
export EXPLORER_APP_ROOT=${EXPLORER_APP_ROOT:-dist}

node ${EXPLORER_APP_ROOT}/main.js name - hyperledger-explorer &
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// "files": [
// "./app/Explorer.ts"
// ],
"include": ["app/", "app/**/*.json", "main.ts", "sync.js", "swagger.json"],
"include": ["app/", "app/platform/fabric/**/*.json"],
"exclude": ["app/platform/fabric/e2e-test/PTE/"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
Expand All @@ -20,7 +20,7 @@
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "dist/" /* Redirect output structure to the directory. */,
"rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"removeComments": false /* Do not emit comments to output. */,
Expand Down

0 comments on commit a105280

Please sign in to comment.