Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mc-scripts): local login dev for internal usage #2626

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fuzzy-comics-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-frontend/mc-dev-authentication': patch
'@commercetools-frontend/mc-scripts': patch
---

Fix dev middleware usage for local login flow (internal usage only)"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function createMcDevAuthenticationMiddleware(
if (request.originalUrl === '/api/graphql') {
response.statusCode = 404;
response.setHeader('Content-Type', 'application/json');
response.end(
response.send(
JSON.stringify({
message: `This GraphQL endpoint is only available in production in the [Merchant Center Proxy Router](https://docs.commercetools.com/custom-applications/concepts/merchant-center-proxy-router). Please check that you are not calling this endpoint in development mode.`,
})
Expand All @@ -42,7 +42,7 @@ function createMcDevAuthenticationMiddleware(
if (isDevAuthenticationMiddlewareDisabled) {
next();
} else {
response.end(htmlLogin);
response.send(htmlLogin);
}
return;
}
Expand All @@ -52,7 +52,7 @@ function createMcDevAuthenticationMiddleware(
if (isDevAuthenticationMiddlewareDisabled) {
next();
} else {
response.end(htmlLogin);
response.send(htmlLogin);
}
return;
}
Expand All @@ -62,7 +62,7 @@ function createMcDevAuthenticationMiddleware(
if (isDevAuthenticationMiddlewareDisabled) {
next();
} else {
response.end(htmlLogout);
response.send(htmlLogout);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ module.exports = ({ port, publicPath }) => ({
hot: true,
https: false,
port,
// Enable HTTPS if the HTTPS environment variable is set to 'true'
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
setupMiddlewares(middlewares, devServer) {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}

middlewares.push(createMcDevAuthenticationMiddleware(applicationConfig));
devServer.app.use(createMcDevAuthenticationMiddleware(applicationConfig));
Comment on lines -55 to +53
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix. Apparently using the middlewares list didn't really work as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, I read the documentation to verify but it also does this. When debugging the production build on the middlewares, the only thing I noticed it that it wasn't called.


return middlewares;
},
Expand Down