From 601755f17a208198d3661ccd211a39f7b2af5044 Mon Sep 17 00:00:00 2001 From: michael shanks Date: Fri, 19 Jul 2019 08:13:39 +0100 Subject: [PATCH] routes for serving UI, now tested --- .../appPackages/testApp/dist/package.tar.gz | Bin 1248 -> 1574 bytes .../appPackages/testApp/ui/main/public/app.js | 1 + .../testApp/ui/main/public/index.html | 3 ++ .../testApp/ui/unauthenticated/public/app.js | 1 + .../ui/unauthenticated/public/index.html | 3 ++ packages/server/middleware/routers.js | 4 -- packages/server/tests/all.spec.js | 2 + packages/server/tests/serveui.js | 48 ++++++++++++++++++ packages/server/utilities/createAppPackage.js | 8 +-- 9 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 packages/server/appPackages/testApp/ui/main/public/app.js create mode 100644 packages/server/appPackages/testApp/ui/main/public/index.html create mode 100644 packages/server/appPackages/testApp/ui/unauthenticated/public/app.js create mode 100644 packages/server/appPackages/testApp/ui/unauthenticated/public/index.html create mode 100644 packages/server/tests/serveui.js diff --git a/packages/server/appPackages/testApp/dist/package.tar.gz b/packages/server/appPackages/testApp/dist/package.tar.gz index 1115b0e5a8d825e19ae8f7c57e693010226add4e..95fb5bba0215fecfbc40dc2b39ffbbdd836c11a4 100644 GIT binary patch literal 1574 zcmV+>2HE)^iwFP!000003hi0zZ`(Ey@8<&jA2?w^9n7^Y$+k8(Ef6Fv7Hmy}#o3o4 zXc>vNSx}-TQh6Zo|Gp#Thn{xa+Rh$2Ah1my@4>s@@yN8E?VdWFPQTwr>Jupcnfx&A zp4qkfw%K)1r{mbBiJtZLVB51;NF0GF-zz8Y+`ojd>k=V8GjciSMrZ`%;#>W936GQ`#+~xgH zqSmf-Ib+0?fEHtVHN9#YH=tkr8g!;ljq+;3VR%ADG@#1xr>XzlZqL#6-|ktC<#cuZ zx1GBF?}Hv*JV(fwPy$$VCr}rV9)YpsFhEAcxip%y!6fB#gYJYfFCviX=uGa1?CMR58GR*tGsdc>tZX6FpMI+3g*S3WWHx*Er=Hr8{ER-ND^>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xQEX0)Je@LL7;p~mSi5u0S2 z<0st3CQ=+pTt#s`E-=ZgfsZU%8YG-BCRT#1h!t-q#pIdYJF`vh8Tko!Heul0bnJrH zu>|exNSH~EQlPQ=JC^SVy(P)>f=VO`(#^?g`ypr9ti2gs-o1Ajg^&6A{4(|BUIOxV zM?7|fA@|xovO-z=TNtfXpC_aeqQYd~79J!ygE?I=8LMOb_fzVSGSN&^4);g-x+;xj zld^CRBpX-K@_zc{AH2xl67Uz6xo;iUeE;VSTyN-lBi#S-Z@7Q|_Ye^Ac*cZ%^LKwb zuFC&t&|Clh>to(~n18P~*#G`}5Wvx`4Vh~4f++YqW(r!)R6B>y?aT{hfcr}a&hf4> zmZXK`Q#Ly!FMcDf^{}=Rx3n`C2P~NosxO3()cKXOxl)o;Ol8@oOUeupuq5x544H;j z3vV3B7tmJl6_=bQCJR&DN#6=tt*tMet^sXyw}WdK?f$q?o_yJ;Z<7@WUk11lO`OS5{N^5RJjAG<>Ku!lYTSK%8m Kqua9p9smGa7ji}b diff --git a/packages/server/appPackages/testApp/ui/main/public/app.js b/packages/server/appPackages/testApp/ui/main/public/app.js new file mode 100644 index 0000000000..aac43737fe --- /dev/null +++ b/packages/server/appPackages/testApp/ui/main/public/app.js @@ -0,0 +1 @@ +console.log("test app 1 - main"); \ No newline at end of file diff --git a/packages/server/appPackages/testApp/ui/main/public/index.html b/packages/server/appPackages/testApp/ui/main/public/index.html new file mode 100644 index 0000000000..a4d1b8d52b --- /dev/null +++ b/packages/server/appPackages/testApp/ui/main/public/index.html @@ -0,0 +1,3 @@ + + MAIN - TEST APP 1 + \ No newline at end of file diff --git a/packages/server/appPackages/testApp/ui/unauthenticated/public/app.js b/packages/server/appPackages/testApp/ui/unauthenticated/public/app.js new file mode 100644 index 0000000000..f8bec72a8d --- /dev/null +++ b/packages/server/appPackages/testApp/ui/unauthenticated/public/app.js @@ -0,0 +1 @@ +console.log("test app 1 - unauthenticated"); diff --git a/packages/server/appPackages/testApp/ui/unauthenticated/public/index.html b/packages/server/appPackages/testApp/ui/unauthenticated/public/index.html new file mode 100644 index 0000000000..d8e48c1d54 --- /dev/null +++ b/packages/server/appPackages/testApp/ui/unauthenticated/public/index.html @@ -0,0 +1,3 @@ + + UNAUTHENTICATED - TEST APP 1 + \ No newline at end of file diff --git a/packages/server/middleware/routers.js b/packages/server/middleware/routers.js index 583b0c694c..564ce42dfd 100644 --- a/packages/server/middleware/routers.js +++ b/packages/server/middleware/routers.js @@ -69,10 +69,6 @@ module.exports = (config, app) => { await send(ctx, path, { root: builderPath }); } }) - .get("/:appname", async (ctx) => { - ctx.response.status = StatusCodes.OK; - ctx.response.body = "UI Served Here"; - }) .post("/:appname/api/authenticate", async (ctx, next) => { const user = await ctx.master.authenticate( ctx.sessionId, diff --git a/packages/server/tests/all.spec.js b/packages/server/tests/all.spec.js index 72b4837930..9ff855e429 100644 --- a/packages/server/tests/all.spec.js +++ b/packages/server/tests/all.spec.js @@ -2,6 +2,7 @@ const app = require("./testApp")(); const authenticateMaster = require("./authenticate"); const createNewApp = require("./createNewApp"); const multipleInstances = require("./multipleInstances"); +const serveui = require("./serveui"); beforeAll(async () => await app.start()) @@ -11,5 +12,6 @@ describe("authenticateMaster", () => authenticateMaster(app, "_master", "masterO describe("createNewApp", () => createNewApp(app)); describe("authenticateTestApp", () => authenticateMaster(app, "testApp", "testAppUser1")); describe("multipleInstances", () => multipleInstances(app)); +describe("serveUi", () => serveui(app)); diff --git a/packages/server/tests/serveui.js b/packages/server/tests/serveui.js new file mode 100644 index 0000000000..c8ef0d5644 --- /dev/null +++ b/packages/server/tests/serveui.js @@ -0,0 +1,48 @@ +const statusCodes = require("../utilities/statusCodes"); +const { readFile } = require("../utilities/fsawait"); + +module.exports = (app) => { + + it("should serve unauthenticated index.html as default", async () => { + const response = await app.get("/testApp") + .expect(statusCodes.OK); + + const expectedIndexHtml = await readFile("appPackages/testApp/ui/unauthenticated/public/index.html", "utf8"); + + expect(response.text).toBe(expectedIndexHtml); + + }); + + it("should serve specified files when unauthenticated", async () => { + const response = await app.get("/testApp/app.js") + .expect(statusCodes.OK); + + const expectedFile = await readFile("appPackages/testApp/ui/unauthenticated/public/app.js", "utf8"); + + expect(response.text).toBe(expectedFile); + + }); + + it("should serve main index.html as default when authenticated", async () => { + const response = await app.get("/testApp") + .set("cookie", app.credentials.testAppUser1.cookie) + .expect(statusCodes.OK); + + const expectedIndexHtml = await readFile("appPackages/testApp/ui/main/public/index.html", "utf8"); + + expect(response.text).toBe(expectedIndexHtml); + + }); + + it("should serve specified files when authenticated", async () => { + const response = await app.get("/testApp/app.js") + .set("cookie", app.credentials.testAppUser1.cookie) + .expect(statusCodes.OK); + + const expectedFile = await readFile("appPackages/testApp/ui/main/public/app.js", "utf8"); + + expect(response.text).toBe(expectedFile); + + }); + +} \ No newline at end of file diff --git a/packages/server/utilities/createAppPackage.js b/packages/server/utilities/createAppPackage.js index cdea3d90f0..68a8ee4edf 100644 --- a/packages/server/utilities/createAppPackage.js +++ b/packages/server/utilities/createAppPackage.js @@ -64,10 +64,10 @@ const applictionVersionPath = (appname, versionId) => join("..", getRuntimePackageDirectory(appname, versionId)) const publicPaths = (appPath) => ({ - mainUiPath: join( - appPath, "ui", "main", "public"), - unauthenticatedUiPath: join( - appPath, "ui", "unauthenticated", "public") + mainUiPath: resolve(join( + __dirname, appPath, "ui", "main", "public")), + unauthenticatedUiPath: resolve(join( + __dirname, appPath, "ui", "unauthenticated", "public")) });