Skip to content

Commit

Permalink
FORMS-1364 CORS for production and localhost (bcgov#1533)
Browse files Browse the repository at this point in the history
* remove cors verify in openshift

* no message

* localhost cors, test on openshift

* remove a console log

* fix devcontainer to load components libraries, remove the unused local keycloak

* Revert "fix devcontainer to load components libraries, remove the unused local keycloak"

This reverts commit 7addc85.

* need formio libraries installed

Signed-off-by: Jason Sherman <[email protected]>

---------

Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology authored Dec 6, 2024
1 parent 63fd4bd commit 57326a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
8 changes: 6 additions & 2 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ CHEFS_LOCAL_DIR=${WORKSPACE_DIR}/.devcontainer/chefs_local
npm install knex -g
npm install jest -g

# install app libraries, prepare for app development and debugging...
cd app
# install components/formio libraries, prepare for ux development and debugging...
cd components
npm install

# install app libraries, prepare for app development and debugging...
cd ../app
npm install

# install frontend libraries, prepare for ux development and debugging...
Expand Down
8 changes: 7 additions & 1 deletion app/src/forms/bcgeoaddress/routes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const cors = require('cors');
const routes = require('express').Router();
const { Development } = require('../common/constants');

const controller = require('./controller');

// need to allow cors for OPTIONS call (localhost only)
// formio component will call OPTIONS pre-flight
routes.options('/advance/address', cors({ origin: Development.LOCALHOST_ORIGIN }));

routes.get('/address', async (req, res, next) => {
await controller.searchBCGeoAddress(req, res, next);
});

routes.get('/advance/address', async (req, res, next) => {
routes.get('/advance/address', cors({ origin: Development.LOCALHOST_ORIGIN }), async (req, res, next) => {
await controller.advanceSearchBCGeoAddress(req, res, next);
});

Expand Down
3 changes: 3 additions & 0 deletions app/src/forms/common/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = Object.freeze({
Development: {
LOCALHOST_ORIGIN: 'http://localhost:5173',
},
EmailProperties: {
FROM_EMAIL: '[email protected]',
},
Expand Down
7 changes: 4 additions & 3 deletions app/src/forms/proxy/routes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const cors = require('cors');
const routes = require('express').Router();
const { Development } = require('../common/constants');

const { currentUser } = require('../auth/middleware/userAccess');
const controller = require('./controller');

// need to allow cors for OPTIONS call
// need to allow cors for OPTIONS call (localhost only)
// formio component will call OPTIONS pre-flight
routes.options('/external', cors());
routes.options('/external', cors({ origin: Development.LOCALHOST_ORIGIN }));

// called with encrypted headers, no current user!!!
routes.get('/external', cors(), async (req, res, next) => {
routes.get('/external', cors({ origin: Development.LOCALHOST_ORIGIN }), async (req, res, next) => {
await controller.callExternalApi(req, res, next);
});

Expand Down

0 comments on commit 57326a6

Please sign in to comment.