Ensure web_base does not end in /

This commit is contained in:
Joscha 2023-08-13 19:57:23 +02:00
parent 18e35184a5
commit 30ddf1e9b2
4 changed files with 23 additions and 19 deletions

View file

@ -146,14 +146,11 @@ impl ConfigFile {
}
fn web_base(&self) -> String {
let mut base = self.web.base.clone();
if !base.starts_with('/') {
base.insert(0, '/');
}
if !base.ends_with('/') {
base.push('/');
}
base
self.web
.base
.strip_suffix('/')
.unwrap_or(&self.web.base)
.to_string()
}
fn web_worker_token(&self) -> String {
@ -210,14 +207,21 @@ impl ConfigFile {
// TODO Url functions
#[derive(Clone)]
pub struct WorkerServerConfig {
/// Never ends with a `/`.
/// Always ends without a `/`.
///
/// This means that you can prefix the url onto an absolute path and get a
/// correct url.
pub url: String,
pub token: String,
}
#[derive(Clone)]
pub struct Config {
/// Always starts and ends with a `/`.
/// Always ends without a `/` (prioritizing the latter).
///
/// This means that you can prefix the base onto an absolute path and get
/// another absolute path. You could also use an url here if you have a
/// weird reason to do so.
pub web_base: String,
pub web_address: SocketAddr,
pub web_worker_token: String,

View file

@ -9,7 +9,7 @@ use super::Base;
ext = "html",
source = "\
{% import \"util.html\" as util %}
<a href=\"{{ root }}commit/{{ hash }}\"
<a href=\"{{ root }}/commit/{{ hash }}\"
class=\"{% call util::commit_class(reachable) %}\"
title=\"{% call util::commit_title(reachable) %}\">
{{ short }}
@ -38,7 +38,7 @@ impl CommitLink {
#[template(
ext = "html",
source = "\
<a href=\"{{ root }}run/{{ id }}\">
<a href=\"{{ root }}/run/{{ id }}\">
Run of {{ short }}
</a>
"
@ -62,7 +62,7 @@ impl RunLink {
#[template(
ext = "html",
source = "\
<a href=\"{{ root }}worker/{{ name }}\">
<a href=\"{{ root }}/worker/{{ name }}\">
{{ name }}
</a>
"