Skip to content

Commit

Permalink
Refs #134485 moved config check within the server condition:
Browse files Browse the repository at this point in the history
- this way we avoid the error where fs isn't found in destroy module from node_modules
  crashing the cypress tests
  • Loading branch information
ichim-david committed Sep 15, 2021
1 parent 782f90d commit 4f39bd6
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/index.js
Expand Up @@ -40,30 +40,30 @@ export const getAPIResourceWithAuth = (req) => {
};

export default (config) => {
const vhPaths = config.settings.virtualHostedPaths || [];

if (__SERVER__ && vhPaths.length) {
const express = require('express');
const middleware = express.Router();

vhPaths.forEach((path) => {
middleware.all(path, function (req, res) {
getAPIResourceWithAuth(req)
.then((resource) => {
res.set('Content-Type', 'text/plain');
res.send(resource);
})
.catch((error) => {
res.status(error.status).send(error);
});
if (__SERVER__) {
const vhPaths = config.settings.virtualHostedPaths || [];
if (vhPaths.length) {
const express = require('express');
const middleware = express.Router();
vhPaths.forEach((path) => {
middleware.all(path, function (req, res) {
getAPIResourceWithAuth(req)
.then((resource) => {
res.set('Content-Type', 'text/plain');
res.send(resource);
})
.catch((error) => {
res.status(error.status).send(error);
});
});
});
});
middleware.id = 'vh-proxy-middleware';
middleware.id = 'vh-proxy-middleware';

config.settings.expressMiddleware = [
...config.settings.expressMiddleware,
middleware,
];
config.settings.expressMiddleware = [
...config.settings.expressMiddleware,
middleware,
];
}
}
return config;
};

0 comments on commit 4f39bd6

Please sign in to comment.