Add separate parameter for URL template

This commit is contained in:
kageru 2019-10-25 22:48:19 +02:00
parent 15bc0d4ce2
commit e7014cb654
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 10 additions and 4 deletions

View File

@ -1,2 +1,4 @@
database.password=12345 database.password=12345
server.domain=localhost server.domain=http://localhost/
# this does nothing because the domain is used if we leave this unspecified
server.pasteurl=http://localhost/

View File

@ -121,7 +121,7 @@ object Routes {
// while also redirecting browser uploads to the newly created paste. // while also redirecting browser uploads to the newly created paste.
// May seem odd to return code 302, but it seems to be the only way. // May seem odd to return code 302, but it seems to be the only way.
response.headers.append(HttpHeaders.Location, uri) response.headers.append(HttpHeaders.Location, uri)
respond(HttpStatusCode.Found, "${config[ServerSpec.domain]}/$uri") respond(HttpStatusCode.Found, "${config[ServerSpec.pasteurl].ifBlank { config[ServerSpec.domain] }}$uri")
return uri return uri
} }

View File

@ -18,6 +18,10 @@ object DatabaseSpec : ConfigSpec() {
object ServerSpec : ConfigSpec() { object ServerSpec : ConfigSpec() {
val port by optional(9092) val port by optional(9092)
// this is needed to return full URLs when uploading via curl and for the AboutPage // For the AboutPage.
// No protocol or trailing slash is added.
val domain by required<String>() val domain by required<String>()
// This is needed to return full URLs when uploading via curl.
// Will use the domain above if unspecified.
val pasteurl by optional<String>("")
} }

View File

@ -7,7 +7,7 @@ import moe.kageru.kodeshare.config.ServerSpec
import moe.kageru.kodeshare.config.config import moe.kageru.kodeshare.config.config
object AboutPage { object AboutPage {
private val domain = "https://${config[ServerSpec.domain]}" private val domain = "${config[ServerSpec.domain]}"
val content = HtmlContent(HttpStatusCode.OK) { val content = HtmlContent(HttpStatusCode.OK) {
head { head {
link(rel = "stylesheet", href = "/style.css", type = "text/css") link(rel = "stylesheet", href = "/style.css", type = "text/css")