Skip to content

Commit

Permalink
AppModel: use fall back URL as preferred Home URL if in single domain
Browse files Browse the repository at this point in the history
This should handle the most common case of a single Grist site with a
single server, removing the need for the user to set up APP_HOME_URL
in this case.
  • Loading branch information
jordigh committed Feb 6, 2025
1 parent a052648 commit 8be3dd1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions app/client/models/AppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,22 +553,28 @@ export function getConfiguredHomeUrl(): string {
}

/**
* Get the home URL, using fallback if on admin page rather
* than trusting back end configuration.
* Get the home URL, using fallback on the admin case and in the
* single-domain case case.
*/
export function getPreferredHomeUrl(): string|undefined {
const gristUrl = urlState().state.get();
if (gristUrl.adminPanel) {
const gristConfig: GristLoadConfig = (window as any).gristConfig;
if (gristUrl.adminPanel || gristConfig.serveSameOrigin) {
// On the admin panel, we should not trust configuration much,
// since we want the user to be able to access it to diagnose
// problems with configuration. So we access the API via the
// site we happen to be on rather than anything configured on
// the back end. Couldn't we just always do this? Maybe!
// It could require adjustments for calls that are meant
// to be site-neutral if the domain has an org encoded in it.
// But that's a small price to pay. Grist Labs uses a setup
// where api calls go to a dedicated domain distinct from all
// other sites, but there's no particular advantage to it.
// the back end.
//
// We can also do this in the common self-hosted case of a single
// domain, no orgs encoded in subdomains.
//
// Couldn't we just always do this? Maybe! It could require
// adjustments for calls that are meant to be site-neutral if the
// domain has an org encoded in it. But that's a small price to
// pay. Grist Labs uses a setup where api calls go to a dedicated
// domain distinct from all other sites, but there's no particular
// advantage to it.
return getFallbackHomeUrl();
}
return getConfiguredHomeUrl();
Expand Down

0 comments on commit 8be3dd1

Please sign in to comment.