This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
feat(index): proxy all modules in a remote module map #4
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anescobar1991
force-pushed
the
feature/proxy-modules
branch
from
February 27, 2020 00:10
fa5f821
to
63d1b22
Compare
anescobar1991
commented
Feb 27, 2020
@@ -119,5 +162,36 @@ export default ({ | |||
// for locally served modules | |||
oneAppDevCdn.use('/modules', express.static(`${localDevPublicPath}/modules`)); | |||
|
|||
// eslint-disable-next-line consistent-return | |||
oneAppDevCdn.get('*', (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is ugly but cannot figure out a different way of doing it, definitely open to feedback!
anescobar1991
commented
Feb 27, 2020
? got(remoteModuleMapUrl).then( | ||
r => JSON.parse(r.body), | ||
? got(remoteModuleMapUrl, { | ||
agent: new ProxyAgent(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works with HTTP_PROXY
, HTTPS_PROXY
, and NO_PROXY
thanks to our old friend @crosscompile's undocumented addition to the proxy-agent lib.
JAdshead
suggested changes
Feb 27, 2020
}, | ||
}, | ||
}, | ||
}; | ||
return supertest(fcdn) | ||
.get('/module-map.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you test that if this is hit multiple times that the module map list does not keep growing
anescobar1991
force-pushed
the
feature/proxy-modules
branch
from
February 27, 2020 23:32
579b60c
to
b610866
Compare
JAdshead
previously approved these changes
Feb 27, 2020
JamesSingleton
previously approved these changes
Feb 27, 2020
anescobar1991
dismissed stale reviews from JamesSingleton and JAdshead
via
February 27, 2020 23:50
06d4afa
anescobar1991
force-pushed
the
feature/proxy-modules
branch
from
February 27, 2020 23:50
b610866
to
06d4afa
Compare
JamesSingleton
approved these changes
Feb 27, 2020
JAdshead
approved these changes
Feb 28, 2020
nellyk
pushed a commit
that referenced
this pull request
Feb 28, 2020
# [3.1.0](v3.0.0...v3.1.0) (2020-02-28) ### Features * **index:** proxy all modules in a remote module map ([#4](#4)) ([c5fb1e7](c5fb1e7))
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem this is solving is that there are times where the modules a remote module map tries to add are not able to be loaded on browsers due to CORS restrictions (many CDNs don't allow localhost as an allowed origin).
Thus without this fix running one app while pointing to a remote module map that does not add
localhost
to their allowed origins for CORS (i.e.npm run start -- --root-module-name=my-root --module-map-url=https://example.com/module-map.json
) does not work because the browser refues to load modules due to CORS.The solution I implemented is to upon proxying to a remote module map storing all the module URLs from said module map in memory, modifying the module map to have all module URLs point back to one-app-dev-cdn, and then on requests to those modules proxy to the original remote module URL.
Validated locally by running One App with a remote module map, with just serving local modules, with a remote module map AND serving local modules, with proxy env vars set, and without proxy env vars set.