Add Https redirect

This commit is contained in:
Alexander Nozik 2022-06-23 11:02:26 +03:00
parent 846c02020b
commit 43bf8e8e96
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
4 changed files with 10 additions and 4 deletions

View File

@ -33,6 +33,7 @@ dependencies {
implementation("io.ktor:ktor-server-host-common:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-http-redirect:$ktorVersion")
implementation("ch.qos.logback:logback-classic:1.2.11")
implementation("space.kscience:dataforge-workspace:$dataforgeVersion")
implementation("space.kscience:dataforge-io-yaml:$dataforgeVersion")

View File

@ -1,7 +1,9 @@
package ru.mipt.spc
import io.ktor.server.application.Application
import io.ktor.server.application.install
import io.ktor.server.application.log
import io.ktor.server.plugins.httpsredirect.HttpsRedirect
import kotlinx.css.CssBuilder
import kotlinx.html.CommonAttributeGroupFacade
import kotlinx.html.style
@ -47,6 +49,8 @@ const val BUILD_DATE_FILE = "/buildDate"
@Suppress("unused")
fun Application.spcModule() {
install(HttpsRedirect)
val context = Context("spc-site") {
plugin(SnarkPlugin)
}

View File

@ -37,7 +37,7 @@ data class SiteData(
return SiteData(snark, emptyData, baseUrlPath, meta)
}
const val INDEX_PAGE_TOKEN: String = "index"
val INDEX_PAGE_TOKEN: NameToken = NameToken("index")
}
}
@ -53,8 +53,9 @@ fun SiteData.resolveRef(name: String): String = if (baseUrlPath.isEmpty()) {
/**
* Resolve a page designated by given name. Depending on rendering specifics, some prefixes or suffixes could be added.
*/
fun SiteData.resolvePage(name: Name): String =
resolveRef(name.tokens.joinToString("/")) + (meta["pageSuffix"].string ?: "")
fun SiteData.resolvePage(name: Name): String {
return resolveRef(name.tokens.joinToString("/")) + (meta["pageSuffix"].string ?: "")
}
/**
*

View File

@ -73,7 +73,7 @@ fun SnarkPlugin.static(path: Path, block: SiteBuilder.() -> Unit) {
this,
baseUrlPath = path.absolutePathString(),
meta = Meta {
"pageSuffix" put "/index.html"
"pageSuffix" put ".html"
}
)
StaticSiteBuilder(base, path).block()