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

HTML served with <img src=http://localhost:3100> even with HOST=10.0.0.1 myst start --keep-host` #342

Open
drewlio opened this issue Mar 23, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@drewlio
Copy link

drewlio commented Mar 23, 2024

Describe the bug

When I have a fresh install with the mystmd-quickstart, and do a HOST=10.0.0.1 myst start --keep-host,

I expect to remotely access http://10.0.01:3000 and have it serve the entire web page,

but instead, while most assets are loaded from relative links and work fine, <img src> tags point to an absolute URL of http://localhost:3100/... (see picture below of incorrect links in the client browser)

image

However, the server is binding to 10.0.0.1 and will serve the asset file. (see picture below of directly accessing the asset URL with the correct domain instead of localhost)

image

This is a problem for people trying to use mystmd through a SSH connection to the big server where they do their computational work and where their Jupyter notebooks live and run.

To try to help, could it be related to the hardcoded localhost below? It seems like this would be fixed if this was a relative path like the other assets.

const CONTENT_CDN = `http://localhost:${CONTENT_CDN_PORT}`;

Reproduce the bug

  1. install mystmd
  2. download the quickstart
  3. set your HOST env variable
  4. myst start --keep-host

List your environment

$ myst --version
v1.1.48

$ myst templates list --site book-theme
ID: site/myst/book-theme
Version: 1.0.0

@drewlio drewlio added the bug Something isn't working label Mar 23, 2024
Copy link

welcome bot commented Mar 23, 2024

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@drewlio
Copy link
Author

drewlio commented Mar 23, 2024

Looks like article-theme does the same thing

const CONTENT_CDN = `http://localhost:${CONTENT_CDN_PORT}`;

@drewlio
Copy link
Author

drewlio commented Mar 23, 2024

On the idea of making it a relative path, RFC3986 Section 5.2.2 says you can't change the port in a relative path. If you need to change the port, you have to specify the entire "authority" (host:port).

@LecrisUT
Copy link

On the idea of making it a relative path, RFC3986 Section 5.2.2 says you can't change the port in a relative path. If you need to change the port, you have to specify the entire "authority" (host:port).

I am not sure this is relevant. myst start controls what host:port are being listened to, and the relative paths should just change according to the paths that are served + the current document/path

About the utils/loders.server.ts, I am not sure if that one is related. I wonder if that one is just used to get the pages. What we are after here is to change the link parser itself, so I think it would be in myst-to-react, maybe somewhere around

function InternalLink({ url, children }: { url: string; children: React.ReactNode }) {
const Link = useLinkProvider();
const site = useSiteManifest();
const page = getPageInfo(site, url);
const baseurl = useBaseurl();
const skipPreview = !page || (!page.description && !page.thumbnail);
if (!page || skipPreview) {
return (
<Link to={withBaseurl(url, baseurl)} prefetch="intent">
{children}
</Link>
);
}
return (
<HoverPopover
card={
<LinkCard
internal
url={url}
title={page.title}
description={page.description}
thumbnail={page.thumbnailOptimized || page.thumbnail}
/>
}
>
<Link to={withBaseurl(url, baseurl)} prefetch="intent">
{children}
</Link>
</HoverPopover>
);
}

@stevejpurves
Copy link
Member

I think this could be on the right track as this is where the url's get re-written based on the CONTENT_CDN and that is what is setting the image paths to localhost.

There is a possible change to make here and a parallel change needed in mystmd to make this work, I think.

@LecrisUT
Copy link

LecrisUT commented Apr 1, 2024

Probably worth mentioning the context for the other discussions in mystmd. A better solution is to keep all of the paths relative (and add .html suffix on .md files) in order to make the static site generation more portable

@stevejpurves
Copy link
Member

I see... tagging these issues executablebooks/mystmd#994 & executablebooks/mystmd#994

so in using relative paths are you suggesting proxying to the content server when running the development server so get around the different port mapping? (I don't follow on the need for the additional .html suffix, though as all content files get .html extensions in the static build -- but I probably need to dig into the other issue a bit more)

@LecrisUT
Copy link

LecrisUT commented Apr 2, 2024

so in using relative paths are you suggesting proxying to the content server when running the development server so get around the different port mapping?

Kinda, basically this fixes both the static site generation and serving behind a reverse-proxy because in both cases it will navigate based on whatever url it was served, beit file://, https://, etc.

I don't follow on the need for the additional .html suffix

For context, you can check: https://mystmd-temp.readthedocs.io/latest/ which was generated from the static builder. (The site is not navigable1). Yes, all html files were downloaded, but the links were those of react which did not add the .html suffix so that they are navigable. On the other hand sphinx always adds .html suffix to the page links, mirroring the .md file structure.

Footnotes

  1. https://github.com/executablebooks/mystmd/issues/984

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants