From f7ea8f4e05bd9fc91554243cee9ca000111eba50 Mon Sep 17 00:00:00 2001 From: Joshua Benjamin Date: Wed, 13 May 2020 22:24:33 -0700 Subject: [PATCH] (+semver: feature) Add processor watcher (#8) Signed-off-by: Joshua Benjamin --- package.json | 2 + server/index.ts | 1 + server/server.ts | 57 ++++--- src/App.tsx | 18 +++ src/Body/ComponentView/ComponentView.tsx | 15 +- src/Body/ProcessorView/OperationCard.tsx | 69 +++++++++ src/Body/ProcessorView/OperationsList.tsx | 36 +++++ src/Body/ProcessorView/ProcessorView.tsx | 149 ++++++++++++++++++ src/Body/ProcessorView/models.ts | 49 ++++++ src/Graphs/Component/Component.stories.tsx | 3 +- src/Graphs/Component/Component.tsx | 27 +++- src/index.tsx | 42 ++++- src/schema.ts | 69 ++++++++- src/types.json | 172 +++++++++++++++++++++ tsconfig.json | 3 +- webpack/webpack.app.config.js | 3 +- yarn.lock | 33 +++- 17 files changed, 712 insertions(+), 36 deletions(-) create mode 100644 src/Body/ProcessorView/OperationCard.tsx create mode 100644 src/Body/ProcessorView/OperationsList.tsx create mode 100644 src/Body/ProcessorView/ProcessorView.tsx create mode 100644 src/Body/ProcessorView/models.ts create mode 100644 src/types.json diff --git a/package.json b/package.json index 4cb3a28..a41823a 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "apollo-boost": "^0.4.7", "apollo-cache-inmemory": "^1.6.5", "apollo-link-http": "^1.5.17", + "apollo-link-ws": "^1.0.20", "awesome-typescript-loader": "^5.2.1", "cytoscape": "^3.14.0", "cytoscape-cose-bilkent": "^4.1.0", @@ -32,6 +33,7 @@ "react-scripts": "^3.4.1", "source-map-loader": "^0.2.4", "styled-components": "^5.0.1", + "subscriptions-transport-ws": "^0.9.16", "ts-loader": "^7.0.2", "ts-node": "^8.10.1", "typescript": "^3.8.3", diff --git a/server/index.ts b/server/index.ts index d328bd5..6f5433c 100644 --- a/server/index.ts +++ b/server/index.ts @@ -10,5 +10,6 @@ if (graphQL == undefined || graphQL == '') { throw 'KAFMESH_URL is not set'; } +console.log('kafmesh url: ' + graphQL); const server = new Server(app, graphQL); server.start(Number(port)); diff --git a/server/server.ts b/server/server.ts index 4b29c4c..d3a2d5b 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1,35 +1,48 @@ import { Express, Request, Response } from 'express'; import express from 'express'; import * as path from 'path'; -import proxy from 'express-http-proxy'; +import proxy from 'http-proxy'; import http from 'http'; import * as terminus from '@godaddy/terminus'; export class Server { private app: Express; + private proxy: proxy; + private graphQLServer: string; constructor(app: Express, graphQLServer: string) { this.app = app; + this.graphQLServer = graphQLServer; + + this.proxy = proxy.createProxy({ + ws: true, + toProxy: true, + changeOrigin: true, + autoRewrite: true, + headers: { + host: graphQLServer + } + }); + + this.proxy.on('error', function(err, req, res) { + res.end('Something went wrong. And we are reporting a custom error message.'); + }); this.app.use(express.static(path.resolve('./') + '/app')); - this.app.use( - '/query', - proxy(graphQLServer, { - proxyReqPathResolver: function(req) { - return '/query'; - } - }) - ); - - this.app.use( - '/playground', - proxy(graphQLServer, { - proxyReqPathResolver: function(req) { - return '/'; - } - }) - ); + this.app.use('/query', (req, resp) => { + this.proxy.web(req, resp, { + ignorePath: true, + target: 'http://' + graphQLServer + '/query' + }); + }); + + this.app.use('/playground', (req, resp) => { + this.proxy.web(req, resp, { + ignorePath: true, + target: 'http://' + graphQLServer + '/' + }); + }); this.app.all('*', (req: Request, res: Response): void => { res.sendFile(path.resolve('./') + '/app/index.html'); @@ -52,6 +65,14 @@ export class Server { healthChecks: { '/healthcheck': this.onHealthCheck }, onSignal: this.onSignal }); + + var app = this; + server.on('upgrade', function(req, socket, head) { + app.proxy.ws(req, socket, head, { + target: 'ws://' + app.graphQLServer + }); + }); + console.log('started server'); server.listen(port, () => console.log(`Server listening on port ${port}!`)); } diff --git a/src/App.tsx b/src/App.tsx index 586411c..32f933e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import Header from './Header'; import ServicesView from './Body/ServicesView/ServicesView'; import ServiceView from './Body/ServiceView/ServiceView'; import ComponentView from './Body/ComponentView/ComponentView'; +import ProcessorView, { Props } from './Body/ProcessorView/ProcessorView'; import Footer from './Footer'; const AppContainer = styled.div` @@ -35,7 +36,9 @@ const App = () => ( } /> + } /> } /> + } />