Skip to content

Commit

Permalink
Fix proxy middleware and public path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbrazier committed Mar 7, 2020
1 parent 0107520 commit 04a95dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
type="application/opensearchdescription+xml"
/>
<title>Go</title>
<script src="/config.js"></script>
<script src="%PUBLIC_URL%/config.js"></script>
</head>
<body>
<noscript>
Expand Down
23 changes: 10 additions & 13 deletions frontend/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
const { createProxyMiddleware } = require('http-proxy-middleware');

const excludedTypes = ['.js', '.css', '.json', '.ico', '.map', 'png', 'svg'];
const filter = pathname =>
!pathname.startsWith('/go') &&
!excludedTypes.some(type => pathname.endsWith(type));

module.exports = function setupProxy(app) {
app.use('/', (req, res, next) => {
if (
req.path.startsWith('/go') ||
excludedTypes.some(type => req.path.endsWith(type))
) {
return next();
}
return createProxyMiddleware({ target: 'http://localhost:1323' })(
req,
res,
next,
);
});
app.use(
'/',
createProxyMiddleware(filter, {
target: 'http://localhost:1323',
}),
);
};

0 comments on commit 04a95dc

Please sign in to comment.