fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Add support for custom root paths

Open RobGarrard opened this issue 2 years ago • 2 comments

Howdy,

Short version:

I'm trying to host my Fresh app at https://my-domain-name/homepage. How do I tell Fresh to use the /homepage routing extension , analogous to putting the "homepage" address into package.json for a React app?

Longer version:

I have an EC2 set up running Apache that has some Plotly Dash apps, and I'm trying to use Fresh to build a simple home page for it. (I have very little web-dev experience, this is more a learning exercise). I want this page to be accessible at https://my-domain-name/homepage.

In my Apache config I've added the usual reverse proxy statements:

ProxyPass /homepage http://127.0.0.1:8000 ProxyPassReverse /homepage http://127.0.0.1:8000

(I've got this set up for some Plotly Dash apps and they all work fiine)

I created a new Fresh boilerplate repo (with the Lemon image and the Counter) and ran it with deno task start (so running on port 8000 by default).

When I look at localhost:8000 on this EC2, all is well. App is running normally.

When I look at http://my-domain-name/homepage, the html objects show up but the islands and static assets don't load. When I inspct the network traffic, the first request "GET my-domain-name/homepage" returns 200. But all the subsequent requests to fetch the static assets and JS files are like:

"GET my-domain-name/_frsh/refresh.js" "GET my-domain-name/logo.svg?__frsh_c=927807f6-b7ac-4bb4-b2ab-d55181719490" etc

returning 404s because they're all without the /homepage/ extension. So how do I tell Fresh to put the /homepage/ extension on these follow up requests?

Cheers.

RobGarrard avatar Sep 05 '22 07:09 RobGarrard

Fresh does not support this yet. We'll need to add a feature to specify a custom root path in the FreshOptions.

lucacasonato avatar Sep 05 '22 12:09 lucacasonato

No worries. Thanks!

RobGarrard avatar Sep 05 '22 21:09 RobGarrard

It would be nice to configure this on a per-request basis so that we can change the path under which a Fresh application is accessed without having to re-deploy the application. What about adding support for custom root paths via a header in addition to a static option?

cowboyd avatar Jan 12 '23 19:01 cowboyd

I created a pull request with a version of this strategy working.... Happy to move things forward in this or in a different direction.

cowboyd avatar Jan 13 '23 20:01 cowboyd

What is the status of this @cowboyd @lucacasonato? We are currently building a new app based on Fresh, but we need to add a custom subpath due to the reverse-proxy configuration.

e.g. https://mysite.com/web <- root of the application

I would be happy to supply a PR if we have an idea of a good solution.

groenborg avatar Jun 12 '23 12:06 groenborg