From 2505fa52841cb45beb016fed07df54c4b6ef78f9 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 9 Jan 2019 14:22:57 +0000 Subject: [PATCH] feat: add development mode to cockpit --- package.json | 2 ++ src/lib/modules/api/server.ts | 9 ++++++++- yarn.lock | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 84e5e61b5..ea620a7e3 100644 --- a/package.json +++ b/package.json @@ -103,6 +103,7 @@ "ethereumjs-util": "6.0.0", "ethereumjs-wallet": "0.6.0", "express": "4.16.3", + "express-http-proxy": "1.5.0", "express-ws": "4.0.0", "file-loader": "2.0.0", "find-up": "2.1.0", @@ -194,6 +195,7 @@ "@types/body-parser": "1.17.0", "@types/cors": "2.8.4", "@types/express": "4.16.0", + "@types/express-http-proxy": "1.5.0", "@types/express-ws": "3.0.0", "@types/globule": "1.1.3", "@types/handlebars": "4.0.39", diff --git a/src/lib/modules/api/server.ts b/src/lib/modules/api/server.ts index 5714dea19..74e1b57ab 100644 --- a/src/lib/modules/api/server.ts +++ b/src/lib/modules/api/server.ts @@ -1,6 +1,7 @@ import bodyParser from "body-parser"; import cors from "cors"; import express, { NextFunction, Request, Response } from "express"; +import proxy from "express-http-proxy"; import expressWs from "express-ws"; import helmet from "helmet"; import * as http from "http"; @@ -96,7 +97,13 @@ export default class Server { this.embark.events.on("plugins:register:api", (callDescription: CallDescription) => this.registerCallDescription(instance, callDescription)); - const ui = express.static(path.join(__dirname, "../../../../embark-ui/build")); + let ui: express.RequestHandler; + if (process.env.DEVELOPMENT) { + ui = proxy("http://localhost:3000"); + } else { + ui = express.static(path.join(__dirname, "../../../../embark-ui/build")); + } + instance.app.use("/", ui); instance.app.use("/*", ui); diff --git a/yarn.lock b/yarn.lock index 174f53d1b..baee4c2e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -870,6 +870,13 @@ resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86" integrity sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA== +"@types/express-http-proxy@1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@types/express-http-proxy/-/express-http-proxy-1.5.0.tgz#0543348e5845c4c87f6e17a834f4962a75ea4579" + integrity sha512-gPo4mt1//QMitFvyw0AXrjtmp1xrGQtxLNJdRcXD4QkTv4RvEFXU01/8lYlFTsNr8AL/10QyRdrBeC9Ow9WuSA== + dependencies: + "@types/express" "*" + "@types/express-serve-static-core@*": version "4.16.0" resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.16.0.tgz#fdfe777594ddc1fe8eb8eccce52e261b496e43e7" @@ -3680,7 +3687,7 @@ debug@3.1.0, debug@=3.1.0: dependencies: ms "2.0.0" -debug@^3.1.0: +debug@^3.0.1, debug@^3.1.0: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== @@ -4193,6 +4200,11 @@ es6-error@^4.0.1: resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d" integrity sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg== +es6-promise@^4.1.1: + version "4.2.5" + resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.5.tgz#da6d0d5692efb461e082c14817fe2427d8f5d054" + integrity sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg== + escape-html@~1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" @@ -4830,6 +4842,15 @@ expect-ct@0.1.1: resolved "https://registry.yarnpkg.com/expect-ct/-/expect-ct-0.1.1.tgz#de84476a2dbcb85000d5903737e9bc8a5ba7b897" integrity sha512-ngXzTfoRGG7fYens3/RMb6yYoVLvLMfmsSllP/mZPxNHgFq41TmPSLF/nLY7fwoclI2vElvAmILFWGUYqdjfCg== +express-http-proxy@1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/express-http-proxy/-/express-http-proxy-1.5.0.tgz#27aca3898e2f0cb9aff2e1d00c93ec27014254a2" + integrity sha512-rYXjOj+ldSDZdmCxRDX/7o6Oxtz45sS9l4QTsvqm+ZFxqI5xTA4usMMP4FBrrKTpDPuQkI2YVda+0LvkJhPu7A== + dependencies: + debug "^3.0.1" + es6-promise "^4.1.1" + raw-body "^2.3.0" + express-ws@4.0.0, express-ws@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/express-ws/-/express-ws-4.0.0.tgz#dabd8dc974516418902a41fe6e30ed949b4d36c4" @@ -9292,7 +9313,7 @@ raw-body@2.3.2: iconv-lite "0.4.19" unpipe "1.0.0" -raw-body@2.3.3: +raw-body@2.3.3, raw-body@^2.3.0: version "2.3.3" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.3.tgz#1b324ece6b5706e153855bc1148c65bb7f6ea0c3" integrity sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==