From 7b0a2741f006b670f2440ae7b08effc29a35e551 Mon Sep 17 00:00:00 2001 From: Josh Salisbury Date: Wed, 30 Sep 2020 10:21:13 -0500 Subject: [PATCH] Fix deployed UI frontend issues (#39) * Fix deployed UI frontend issues * Serve the static frontend before applying the auth middleware * The CSP of the backend forces us to set INLINE_RUNTIME_CHUNK to false. See https://create-react-app.dev/docs/advanced-configuration/ * Set sandbox branch to this branch * Rename tests to match what they test --- .circleci/config.yml | 2 +- frontend/package.json | 4 ++-- frontend/src/__tests__/App.js | 2 +- src/index.js | 8 ++++---- src/index.test.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 493c825e8e..1aa4078f4b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,7 +106,7 @@ parameters: default: "main" type: string sandbox_git_branch: # change to feature branch to test deployment - default: "sj-add-callback-to-manifest" + default: "js-fix-deployed-ui-login" type: string jobs: build: diff --git a/frontend/package.json b/frontend/package.json index dd43541405..2e2684d097 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -22,8 +22,8 @@ }, "scripts": { "start": "react-scripts start", - "build:local": "react-scripts build", - "build": "react-scripts build && mv build/ ../build/server/client", + "build:local": "INLINE_RUNTIME_CHUNK=false react-scripts build", + "build": "INLINE_RUNTIME_CHUNK=false react-scripts build && mv build/ ../build/server/client", "eject": "react-scripts eject", "test": "react-scripts test", "test:ci": "cross-env JEST_JUNIT_OUTPUT_DIR=reports JEST_JUNIT_OUTPUT_NAME=unit.xml CI=true yarn test --coverage --reporters=default --reporters=jest-junit", diff --git a/frontend/src/__tests__/App.js b/frontend/src/__tests__/App.js index c5c9b4856f..02c2ab843b 100644 --- a/frontend/src/__tests__/App.js +++ b/frontend/src/__tests__/App.js @@ -37,7 +37,7 @@ describe('App', () => { render(); }); - it('displays the logout button', async () => { + it('displays the login button', async () => { expect(await waitFor(() => screen.getByText('HSES Login'))).toBeVisible(); }); }); diff --git a/src/index.js b/src/index.js index bb2f7933c2..9c68d936b4 100644 --- a/src/index.js +++ b/src/index.js @@ -38,6 +38,10 @@ app.use(session({ resave: false, })); +if (process.env.NODE_ENV === 'production') { + app.use(express.static(path.join(__dirname, 'client'))); +} + authMiddleware.unless = unless; // TODO: update unless to replace `oauth1CallbackPath with `join('/api', oauth2CallbackPath)` // once our oauth callback has been updated @@ -86,10 +90,6 @@ app.get(oauth2CallbackPath, async (req, res) => { app.use('/api', router); -if (process.env.NODE_ENV === 'production') { - app.use(express.static(path.join(__dirname, 'client'))); -} - const server = app.listen(process.env.PORT || 8080, () => { logger.info('listening on 8080'); }); diff --git a/src/index.test.js b/src/index.test.js index 3928f715ed..8352fd290d 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -2,7 +2,7 @@ import request from 'supertest'; import server from './index'; describe('Root', () => { - test('Redirects to login if user is not logged in', async () => { + test('Responds with a 401 (Unauthorized) if user is not logged in', async () => { const response = await request(server).get('/'); expect(response.status).toBe(401); });