Skip to content

Commit

Permalink
Use a factory function to create proxy middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-lee committed Apr 7, 2023
1 parent b53025c commit 02f8dc0
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions karma.conf.js
Expand Up @@ -124,25 +124,28 @@ module.exports = function karma(config) {
: [],

plugins: [
'karma-*',
...config.plugins,

{
// A middleware that proxies cspace-services requests to the URL specified by TEST_BACKEND.
// This is used to avoid CORS issues when connecting to a CSpace server from an integration
// test running in a browser.

'middleware:proxy': ['value', createProxyMiddleware({
target: TEST_BACKEND,
pathFilter: '/cspace-services',
changeOrigin: true,
headers: {
origin: TEST_BACKEND,
},
onProxyRes: (proxyRes) => {
// Prevent the browser from showing the login prompt.
// eslint-disable-next-line no-param-reassign
delete proxyRes.headers['www-authenticate'];
},
})],
'middleware:proxy': ['factory', function create() {
return createProxyMiddleware({
target: TEST_BACKEND,
pathFilter: '/cspace-services',
changeOrigin: true,
headers: {
origin: TEST_BACKEND,
},
onProxyRes: (proxyRes) => {
// Prevent the browser from showing the login prompt.
// eslint-disable-next-line no-param-reassign
delete proxyRes.headers['www-authenticate'];
},
});
}],
},
],
});
Expand Down

0 comments on commit 02f8dc0

Please sign in to comment.