trunk icon indicating copy to clipboard operation
trunk copied to clipboard

confusion in public_url

Open tiye opened this issue 2 years ago • 2 comments

when passed from CLI, the config of public_url is checked and ensure it starts with /: https://github.com/thedodd/trunk/blob/v0.15.0/src/config/models.rs#L30 https://github.com/thedodd/trunk/blob/v0.15.0/src/common.rs#L25-L29

/// Ensure the given value for `--public-url` is formatted correctly.
pub fn parse_public_url(val: &str) -> String {
    let prefix = if !val.starts_with('/') { "/" } else { "" };
    let suffix = if !val.ends_with('/') { "/" } else { "" };
    format!("{}{}{}", prefix, val, suffix)
}

however it's not ensured when passing from config file. It's inconsistent.

meanwhile in my case I need to use ./ to make sure it resolves files relative to current path. I suppose it should be valid.

what are the design decisions of Trunk?


update, also noticed the error actually came from the router, which does not allow ./ being used as a path. however the function above also causes confusing issue creating /./ at release build.

thread 'tokio-runtime-worker' panicked at 'Paths must start with a `/`', /Users/me/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.5.7/src/routing/mod.rs:132:13

tiye avatar Jun 14 '22 11:06 tiye

I am running into the same issue. My current workaround is a sed script :see_no_evil:

Looks like there have been previous attempts to fix this. See #361

NiklasEi avatar Jun 18 '22 19:06 NiklasEi

I have the same kind of issue, not sure if this is related to the / at the end

thread 'tokio-runtime-worker' panicked at 'called Result::unwrap() on an Err value: InvalidUriParts(InvalidUri(SchemeMissing))', /home/crunch/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.5.7/src/routing/mod.rs:532:28

AdrienPensart avatar Jun 22 '22 15:06 AdrienPensart

I have a similar issue:

  • public_url = "./" in Trunk.toml replaces /file paths with ./paths, as needed for sub-directory hosting on itch.io
  • --public-url "./" in CLI replaces /file paths with /./file, which is inconsistent and wrong

I was thinking about using Trunk.toml approach, but so far my toml describes quick-start local debug build, while I prefer to specify exceptions for itch.io dist outside the config file (or may I use 2 config files for different builds?).

Does any better solution than sed scripts exist?


UPDATE:

OK, so it is possible to use multiple toml configurations. Therefore, for posterity, my fix is to use public_url in config file:

[build]
public_url = "./"

Example from my repo: https://github.com/beetrootpaul/poc--bevy-pixels-web-game/blob/7d5863fe3e23d21f67266912011e5901217fd411/Trunk.itch_io.toml

and usage:

trunk --config ./Trunk.itch_io.toml build

beetrootpaul avatar Mar 18 '23 12:03 beetrootpaul

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 26 '23 00:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 01 '23 00:10 github-actions[bot]