diff --git a/packages/server/appPackages/testApp/dist/package.tar.gz b/packages/server/appPackages/testApp/dist/package.tar.gz index 1115b0e5a8..95fb5bba02 100644 Binary files a/packages/server/appPackages/testApp/dist/package.tar.gz and b/packages/server/appPackages/testApp/dist/package.tar.gz differ 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")) });