Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

feat(host): flag to use req.host instead of localhost #14

Merged
merged 3 commits into from
May 13, 2020

Conversation

infoxicator
Copy link
Contributor

In order for the browser tests to run the dev-cdn the module map has to point to the host instead of localhost. I have added the flag useHost to be set to true when running browser tests and false as default when using one-app-runner so it points to localhost during local development.

Tested by passing the flag from one-app, building a dev docker image, passing the image local to one-app-runner and running the browser tests. both scenarios worked as expected

@infoxicator infoxicator requested a review from a team as a code owner May 7, 2020 15:23
mtomcal
mtomcal previously approved these changes May 7, 2020
@nellyk
Copy link
Contributor

nellyk commented May 7, 2020

Do we need to mention something in the Readme?

@@ -57,6 +57,7 @@ export default ({
remoteModuleMapUrl,
useLocalModules,
appPort,
useHost,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about adding something like below here. you can probably come up with a better name however

Suggested change
}) => {
}) => {
const hostAddress = useHost ? `http://${req.headers.host}` : `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

had to put it inside the get for the req to be accessible but Implemented your changes here: 1c5a17c

src/index.js Outdated
@@ -106,7 +107,7 @@ export default ({
const remoteModuleMap = JSON.parse(r.body);

const { modules } = remoteModuleMap;
const oneAppDevStaticsAddress = `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}/static`;
const oneAppDevStaticsAddress = useHost ? `http://${req.headers.host}/static` : `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}/static`;
Copy link
Contributor

Choose a reason for hiding this comment

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

continued from comment above -

Suggested change
const oneAppDevStaticsAddress = useHost ? `http://${req.headers.host}/static` : `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}/static`;
const oneAppDevStaticsAddress = `${hostAddress}/static`;

this change can also be applied below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/index.js Outdated
@@ -141,7 +142,7 @@ export default ({
: {},
(useLocalModules ? getLocalModuleMap({
pathToModulemap: path.join(localDevPublicPath, 'module-map.json'),
oneAppDevCdnAddress: `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}`,
oneAppDevCdnAddress: useHost ? `http://${req.headers.host}}` : `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
oneAppDevCdnAddress: useHost ? `http://${req.headers.host}}` : `http://localhost:${process.env.HTTP_ONE_APP_DEV_CDN_PORT}`,
oneAppDevCdnAddress: hostAddress,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@infoxicator
Copy link
Contributor Author

Do we need to mention something in the Readme?

Added documentation to README 1c5a17c

@@ -84,13 +84,23 @@ location where the remote module map is located (i.e. `https://my-domain.com/map

Type: `boolean`

Default: `true`<br>
Whether to use modules from `localDevPublicPath`. Passed as `true` or `false`, defaults to `true`.
Default: `false`<br>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the code this never defaulted to true so I updated the README to reflect

@infoxicator infoxicator merged commit 5e761a7 into master May 13, 2020
@infoxicator infoxicator deleted the feature/use-host branch May 13, 2020 09:42
oneamexbot added a commit that referenced this pull request May 13, 2020
# [3.3.0](v3.2.2...v3.3.0) (2020-05-13)

### Features

* **host:** flag to use req.host instead of localhost ([#14](#14)) ([5e761a7](5e761a7))
@oneamexbot
Copy link
Contributor

🎉 This PR is included in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants