Skip to content

Commit

Permalink
fix(api-server): enables HTML 5 mode for angular front end
Browse files Browse the repository at this point in the history
Also: performance improvement by using compression on the
API server and the front end web server as well.

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed May 19, 2020
1 parent 210df1d commit 05a2e0b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"configure": "lerna clean --yes && lerna bootstrap && npm run build && node ./tools/generate-api-server-config.js",
"start": "node ./packages/bif-cmd-api-server/dist/lib/main/typescript/cmd/bif-api.js --config-file=.config.json",
"start:api-server": "node ./packages/bif-cmd-api-server/dist/lib/main/typescript/cmd/bif-api.js --config-file=.config.json",
"tsc": "lerna exec --stream --ignore '*/*cockpit' -- tsc --project ./tsconfig.json",
"clean": "lerna exec --stream --ignore '*/*cockpit' -- del-cli dist/**",
"build": "npm-run-all --parallel build:frontend build:backend",
Expand Down
43 changes: 43 additions & 0 deletions packages/bif-cmd-api-server/package-lock.json

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

2 changes: 2 additions & 0 deletions packages/bif-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@hyperledger-labs/bif-plugin-keychain-memory": "0.2.0",
"@hyperledger-labs/bif-plugin-kv-storage-memory": "0.2.0",
"body-parser": "1.19.0",
"compression": "1.7.4",
"convict": "5.2.0",
"cors": "2.8.5",
"express": "4.17.1",
Expand All @@ -62,6 +63,7 @@
"uuid": "7.0.2"
},
"devDependencies": {
"@types/compression": "1.7.0",
"@types/convict": "4.2.1",
"@types/cors": "2.8.6",
"@types/express": "4.17.3",
Expand Down
15 changes: 11 additions & 4 deletions packages/bif-cmd-api-server/src/main/typescript/api-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import { Config } from 'convict';
import express, { Express, Request, Response, NextFunction, RequestHandler, Application } from 'express';
import { OpenApiValidator } from 'express-openapi-validator';
import compression from 'compression';
import bodyParser from 'body-parser';
import cors, { CorsOptions } from 'cors';
import { IPluginKVStorage, PluginFactory } from '@hyperledger-labs/bif-core-api';
Expand Down Expand Up @@ -34,14 +35,19 @@ export class ApiServer {
}

async startCockpitFileServer(): Promise<void> {

const app: Express = express();

const cockpitWwwRoot = this.options.config.get('cockpitWwwRoot');
this.log.info(`cockpitWwwRoot: ${cockpitWwwRoot}`);
this.log.info(`wwwRoot: ${cockpitWwwRoot}`);

const resolvedWwwRoot = path.resolve(process.cwd(), cockpitWwwRoot);
this.log.info(`resolvedWwwRoot: ${resolvedWwwRoot}`);

const resolvedIndexHtml = path.resolve(resolvedWwwRoot + '/index.html');
this.log.info(`resolvedIndexHtml: ${resolvedIndexHtml}`);

const app: Express = express();
app.use(compression());
app.use(express.static(resolvedWwwRoot));
app.get('/*', (_, res) => res.sendFile(resolvedIndexHtml));

const cockpitPort: number = this.options.config.get('cockpitPort');
const cockpitHost: string = this.options.config.get('cockpitHost');
Expand All @@ -58,6 +64,7 @@ export class ApiServer {

async startApiServer(): Promise<void> {
const app: Application = express();
app.use(compression());

const corsMiddleware = this.createCorsMiddleware()
app.use(corsMiddleware);
Expand Down

0 comments on commit 05a2e0b

Please sign in to comment.