-
Notifications
You must be signed in to change notification settings - Fork 118
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
Enable hosting the site at non-root #643
Comments
Summary: This will enable components to obtain the path to a static asset, even when the app is not hosted at the root of a server, as outlined in #643. This module will be used for simple assets (images, etc.) and API data (fetches from `/api/**`) alike. Test Plan: Unit tests included; `yarn test` suffices. wchargin-branch: assets-context
Summary: This will enable clients to obtain the path to a static asset, even when the app is not hosted at the root of a server, as outlined in #643. This module will be used for simple assets (images, etc.) and API data (fetches from `/api/**`) alike. This supersedes #663. It includes the logic from that PR (`Assets`) without the React-specific context bindings (`AssetsContext`). Test Plan: Unit tests included; `yarn test` suffices. wchargin-branch: assets-resolver
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Here’s an update about what I'm working on. As part of enabling our site to be served from arbitrary gateways, I've Happily, it is the kind of thing for which it is possible to write I considered adding Flow typedefs to If we eventually ditch PRs to come. :-) |
Summary: See #643 and the module docstring on `createRelativeHistory.js` for context and explanation. This patch adds `history@^3.0.0` as an explicit dependency—previously, we were depending on it only implicitly through `react-router` (which was fine then, but is not now). The dependency is chosen to match the version specified in `react-router`’s `package.json`. Test Plan: Extensive unit tests included, with full coverage; `yarn test` suffices. wchargin-branch: createRelativeHistory
Summary: This will enable clients to obtain the path to a static asset, even when the app is not hosted at the root of a server, as outlined in #643. This module will be used for simple assets (images, etc.) and API data (fetches from `/api/**`) alike. This supersedes #663. It includes the logic from that PR (`Assets`) without the React-specific context bindings (`AssetsContext`). Test Plan: Unit tests included; `yarn test` suffices. wchargin-branch: assets-resolver
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Summary: See #643 and the module docstring on `createRelativeHistory.js` for context and explanation. This patch adds `history@^3.0.0` as an explicit dependency—previously, we were depending on it only implicitly through `react-router` (which was fine then, but is not now). The dependency is chosen to match the version specified in `react-router`’s `package.json`. Test Plan: Extensive unit tests included, with full coverage; `yarn test` suffices. wchargin-branch: createRelativeHistory
Another technical update to explain the latest architecture. Central to this issue is the At some point, however, we need to use the My initial approach to this was to use the React v16.3 <App>
<CredExplorerApp>
<RepositorySelect />
<PagerankTable />
</CredExplorerApp>
</App> then with the contexts model it would be changed to look more like: <AssetsContext.Provider value={assets}>
<App>
<CredExplorerApp>
<AssetsContext.Consumer>
{(assets) => <RepositorySelect assets={assets} />}
</AssetsContext.Consumer>
<PagerankTable />
</CredExplorerApp>
</App>
</AssetsContext.Provider> Thus, any component in the application tree can magically request This is certainly convenient, and while global mutable state is I implemented this design, and it worked in the expected fashion. And even An alternative is to pass down the Integrating this into the router is only slightly weird, and So, I effected this redesign, and it’s working great. In hindsight, it We may in the future want to move back to a context-based system, if |
Summary: This will enable clients to obtain the path to a static asset, even when the app is not hosted at the root of a server, as outlined in #643. This module will be used for simple assets (images, etc.) and API data (fetches from `/api/**`) alike. This supersedes #663. It includes the logic from that PR (`Assets`) without the React-specific context bindings (`AssetsContext`). Test Plan: Unit tests included; `yarn test` suffices. wchargin-branch: assets-resolver
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Summary: This will enable clients to obtain the path to a static asset, even when the app is not hosted at the root of a server, as outlined in #643. This module will be used for simple assets (images, etc.) and API data (fetches from `/api/**`) alike. This supersedes #663. It includes the logic from that PR (`Assets`) without the React-specific context bindings (`AssetsContext`). Test Plan: Unit tests included; `yarn test` suffices. wchargin-branch: assets-resolver
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Summary: This is necessary for #643. If we’re serving `/prototype/index.html`, we need to to use `..` to refer to the root of the site. This patch adds `rootFromPath`, which performs the relevant transformation. (The implementation is trivial, but figuring out exactly what the specification should be was not!) Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: rootFromPath
Summary: This is the first observable step toward #643. Assets whose paths are known as literals at server-side rendering time are now referenced via relative paths. This means that the favicon and JavaScript bundle can be loaded from an arbitrary gateway. The actual bundle code will still only work when loaded from `/`. This commit stands alone so that the enclosing change to the Webpack config can be in as small a change as possible. Test Plan: - Note that `yarn start` still works. - Run `./scripts/build_static_site.sh` to build the site into, say, `/tmp/gateway`. - Run a static web server from `/tmp/gateway/` and note that (a) the paths listed in the page source are relative, and (b) everything works as intended, with no console messages in either Chrome or Firefox. - Run a static web server from `/tmp/` and navigate to `/gateway/` in the browser. Note that the favicon and JavaScript are correctly noted, but that the router raises an error because it is trying to load a non-existent route. (This behavior is unchanged.) wchargin-branch: relative-lexically-static
Summary: As the next step for #643, this patch enables the app to be rendered at non-root gateways by incorporating the relative-path history implementation developed in #666. The app is not fully functional: our React components do not yet know how to resolve assets, and so fetches of resources like the repository will be against the wrong URLs. Test Plan: - Note that `yarn start` still works. - Run `./scripts/build_static_site.sh` to build the site into, say, `/tmp/gateway`. - Run a static web server from `/tmp/gateway/` and note that (a) the paths listed in the page source are relative, and (b) everything works as intended, with no console messages in either Chrome or Firefox. - Run a static web server from `/tmp/` and navigate to `/gateway/` in the browser. Note that the app loads properly, and that refreshes work (i.e., the `pushState` paths are real paths). Note that the repository registry cannot yet be loaded, and so PageRank cannot be run. wchargin-branch: relative-router
Summary: This is the first observable step toward #643. Assets whose paths are known as literals at server-side rendering time are now referenced via relative paths. This means that the favicon and JavaScript bundle can be loaded from an arbitrary gateway. The actual bundle code will still only work when loaded from `/`. This commit stands alone so that the enclosing change to the Webpack config can be in as small a change as possible. Test Plan: - Note that `yarn start` still works. - Run `./scripts/build_static_site.sh` to build the site into, say, `/tmp/gateway`. - Run a static web server from `/tmp/gateway/` and note that (a) the paths listed in the page source are relative, and (b) everything works as intended, with no console messages in either Chrome or Firefox. - Run a static web server from `/tmp/` and navigate to `/gateway/` in the browser. Note that the favicon and JavaScript are correctly noted, but that the router raises an error because it is trying to load a non-existent route. (This behavior is unchanged.) wchargin-branch: relative-lexically-static
Summary: As the next step for #643, this patch enables the app to be rendered at non-root gateways by incorporating the relative-path history implementation developed in #666. The app is not fully functional: our React components do not yet know how to resolve assets, and so fetches of resources like the repository will be against the wrong URLs. Test Plan: - Note that `yarn start` still works. - Run `./scripts/build_static_site.sh` to build the site into, say, `/tmp/gateway`. - Run a static web server from `/tmp/gateway/` and note that (a) the paths listed in the page source are relative, and (b) everything works as intended, with no console messages in either Chrome or Firefox. - Run a static web server from `/tmp/` and navigate to `/gateway/` in the browser. Note that the app loads properly, and that refreshes work (i.e., the `pushState` paths are real paths). Note that the repository registry cannot yet be loaded, and so PageRank cannot be run. wchargin-branch: relative-router
Summary: As the next step for #643, this patch enables the app to be rendered at non-root gateways by incorporating the relative-path history implementation developed in #666. The app is not fully functional: our React components do not yet know how to resolve assets, and so fetches of resources like the repository will be against the wrong URLs. Test Plan: - Note that `yarn start` still works. - Run `./scripts/build_static_site.sh` to build the site into, say, `/tmp/gateway`. - Run a static web server from `/tmp/gateway/` and note that (a) the paths listed in the page source are relative, and (b) everything works as intended, with no console messages in either Chrome or Firefox. - Run a static web server from `/tmp/` and navigate to `/gateway/` in the browser. Note that the app loads properly, and that refreshes work (i.e., the `pushState` paths are real paths). Note that the repository registry cannot yet be loaded, and so PageRank cannot be run. wchargin-branch: relative-router
Summary: This is the last piece of major infrastructure for #643. It will enable components like `Page` and `CredExplorerApp` to receive `Assets` as a prop. A previous iteration of the same functionality used the new Context API in React v16.3. This did a good job of solving the problem in production code, and was convenient. However, it is currently intractable to test with the current state of Enzyme. It’s plausible that this might improve in the future, so if threading down the props becomes to onerous, we might check in to see how our testing libraries are doing. I expect that the threading should not be too bad, given that we do the same thing with `localStore`, which has worked (as far as I’m aware) without a hitch. Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: withAssets
Summary: This commit takes the next step toward #643 by exposing `Assets` to our React components at top level. Components will be expected to pass them down as appropriate; this commit does not add any actual uses. Test Plan: Apply the following patch: ```js diff --git a/src/app/Page.js b/src/app/Page.js index 24c2602..7ac2641 100644 --- a/src/app/Page.js +++ b/src/app/Page.js @@ -24,6 +24,10 @@ export default class Page extends React.Component<{| <Link to="/" className={css(style.navLink, style.navLinkTitle)}> SourceCred </Link> + <img + alt="fav" + src={this.props.assets.resolve("/favicon.png")} + /> </li> {routeData.map(({navTitle, path}) => NullUtil.map(navTitle, (navTitle) => ( ``` Then, observe that the favicon loads correctly and updates across page loads and refreshes in the following situations: - under `yarn start`; - after building the static site and serving from root; - after building the static site and serving from another gateway. wchargin-branch: use-withAssets
Summary: This is the last piece of major infrastructure for #643. It will enable components like `Page` and `CredExplorerApp` to receive `Assets` as a prop. A previous iteration of the same functionality used the new Context API in React v16.3. This did a good job of solving the problem in production code, and was convenient. However, it is currently intractable to test with the current state of Enzyme. It’s plausible that this might improve in the future, so if threading down the props becomes to onerous, we might check in to see how our testing libraries are doing. I expect that the threading should not be too bad, given that we do the same thing with `localStore`, which has worked (as far as I’m aware) without a hitch. Test Plan: Unit tests added; `yarn test` suffices. wchargin-branch: withAssets
Summary: This commit takes the next step toward #643 by exposing `Assets` to our React components at top level. Components will be expected to pass them down as appropriate; this commit does not add any actual uses. Test Plan: Apply the following patch: ```diff diff --git a/src/app/Page.js b/src/app/Page.js index 24c2602..7ac2641 100644 --- a/src/app/Page.js +++ b/src/app/Page.js @@ -24,6 +24,10 @@ export default class Page extends React.Component<{| <Link to="/" className={css(style.navLink, style.navLinkTitle)}> SourceCred </Link> + <img + alt="fav" + src={this.props.assets.resolve("/favicon.png")} + /> </li> {routeData.map(({navTitle, path}) => NullUtil.map(navTitle, (navTitle) => ( ``` Then, observe that the favicon loads correctly and updates across page loads and refreshes in the following situations: - under `yarn start`; - after building the static site and serving from root; - after building the static site and serving from another gateway. wchargin-branch: use-withAssets
Summary: This commit takes the next step toward #643 by exposing `Assets` to our React components at top level. Components will be expected to pass them down as appropriate; this commit does not add any actual uses. Test Plan: Apply the following patch: ```diff diff --git a/src/app/Page.js b/src/app/Page.js index 24c2602..7ac2641 100644 --- a/src/app/Page.js +++ b/src/app/Page.js @@ -24,6 +24,10 @@ export default class Page extends React.Component<{| <Link to="/" className={css(style.navLink, style.navLinkTitle)}> SourceCred </Link> + <img + alt="fav" + src={this.props.assets.resolve("/favicon.png")} + /> </li> {routeData.map(({navTitle, path}) => NullUtil.map(navTitle, (navTitle) => ( ``` Then, observe that the favicon loads correctly and updates across page loads and refreshes in the following situations: - under `yarn start`; - after building the static site and serving from root; - after building the static site and serving from another gateway. wchargin-branch: use-withAssets
Summary: This commit takes the next step toward #643 by exposing `Assets` to our React components at top level. Components will be expected to pass them down as appropriate; this commit does not add any actual uses. Test Plan: Apply the following patch: ```diff diff --git a/src/app/Page.js b/src/app/Page.js index 24c2602..7ac2641 100644 --- a/src/app/Page.js +++ b/src/app/Page.js @@ -24,6 +24,10 @@ export default class Page extends React.Component<{| <Link to="/" className={css(style.navLink, style.navLinkTitle)}> SourceCred </Link> + <img + alt="fav" + src={this.props.assets.resolve("/favicon.png")} + /> </li> {routeData.map(({navTitle, path}) => NullUtil.map(navTitle, (navTitle) => ( ``` Then, observe that the favicon loads correctly and updates across page loads and refreshes in the following situations: - under `yarn start`; - after building the static site and serving from root; - after building the static site and serving from another gateway. wchargin-branch: use-withAssets
Summary: This commit approximately completes the implementation of #643.\* Plugin adapters are now provided an `Assets` object at `load` time, which they can use to resolve their plugin-specific API routes. \* “Approximately” because there are some non-essential pieces of legacy code that should be cleaned up. Test Plan: Unit tests modified, but it would be good to also manually test this. Run `./scripts/build_static_site.sh` to build the site to, say, `/tmp/gateway/`. Then spin up a static HTTP server serving `/tmp/` and navigate to `/gateway/` in the browser. Note that the entire application works. wchargin-branch: use-assets-in-PluginAdapters
Summary: This commit approximately completes the implementation of #643.\* Plugin adapters are now provided an `Assets` object at `load` time, which they can use to resolve their plugin-specific API routes. \* “Approximately” because there are some non-essential pieces of legacy code that should be cleaned up. Test Plan: Unit tests modified, but it would be good to also manually test this. Run `./scripts/build_static_site.sh` to build the site to, say, `/tmp/gateway/`. Then spin up a static HTTP server serving `/tmp/` and navigate to `/gateway/` in the browser. Note that the entire application works. wchargin-branch: use-assets-in-PluginAdapters
Summary: This commit is the next step in #643. It makes the `RepositorySelect` robust to being hosted at arbitrary gateways by accepting `Assets` and resolving the repository registry API route appropriately. Test Plan: Unit tests modified, but it would be good to also manually test this. Run `./scripts/build_static_site.sh` to build the site to, say, `/tmp/gateway/`. Then spin up a static HTTP server serving `/tmp/` and navigate to `/gateway/` in the browser. Note that you can navigate around the application and load the repository registry on the prototype without any console warnings or errors, although you cannot yet load actual graph data. wchargin-branch: use-assets-in-RepositorySelect
Summary: This commit approximately completes the implementation of #643.\* Plugin adapters are now provided an `Assets` object at `load` time, which they can use to resolve their plugin-specific API routes. \* “Approximately” because there are some non-essential pieces of legacy code that should be cleaned up. Test Plan: Unit tests modified, but it would be good to also manually test this. Run `./scripts/build_static_site.sh` to build the site to, say, `/tmp/gateway/`. Then spin up a static HTTP server serving `/tmp/` and navigate to `/gateway/` in the browser. Note that the entire application works. wchargin-branch: use-assets-in-PluginAdapters
Summary: This commit approximately completes the implementation of #643.\* Plugin adapters are now provided an `Assets` object at `load` time, which they can use to resolve their plugin-specific API routes. \* “Approximately” because there are some non-essential pieces of legacy code that should be cleaned up. Test Plan: Unit tests modified, but it would be good to also manually test this. Run `./scripts/build_static_site.sh` to build the site to, say, `/tmp/gateway/`. Then spin up a static HTTP server serving `/tmp/` and navigate to `/gateway/` in the browser. Note that the entire application works. wchargin-branch: use-assets-in-PluginAdapters
Summary: Now that the main functionality of #643 has been implemented, we no longer have any use for the “public URL” property. In fact, its presence is actively harmful, as it suggests that the gateway may be known before runtime, which is confusing and false. Closes #643. Test Plan: Running `yarn start` works. Building the static site works. Invoking `git grep -i 'public.\?url'` finds no matches. wchargin-branch: remove-public-url
Summary: Now that the main functionality of #643 has been implemented, we no longer have any use for the “public URL” property. In fact, its presence is actively harmful, as it suggests that the gateway may be known before runtime, which is confusing and false. Closes #643. Test Plan: Running `yarn start` works. Building the static site works. Invoking `git grep -i 'public.\?url'` finds no matches. Also, `yarn test --full` passes. wchargin-branch: remove-public-url
Summary: Now that the main functionality of #643 has been implemented, we no longer have any use for the “public URL” property. In fact, its presence is actively harmful, as it suggests that the gateway may be known before runtime, which is confusing and false. Closes #643. Test Plan: Running `yarn start` works. Building the static site works. Invoking `git grep -i 'public.\?url'` finds no matches. Also, `yarn test --full` passes. wchargin-branch: remove-public-url
Various portions of the site currently assume that they are being served
from the root of the host. In other words, we assume that the public
path is
/
. This precludes hosting demos from a personal GitHubrepository like
decentralion/sourcecred-demos
.A relatively straightforward fix is to thread the public path
configuration through whitherever it is required. Then, we can specify
the public path at build time: for instance, a demo for the Foo project
might be hosted at
--public-path /sourcecred-demos/foo
.An alternative solution is to use relative paths throughout the
application, so that the public path does not need to be statically
known. This might require some care, but would probably be more robust.
For instance, this would let us serve instances of the site from an IPFS
gateway without needing control over the domain.
The text was updated successfully, but these errors were encountered: