带有 ktor 的静态目录 - 不在 "mysite.com/static/..." 下
Static directory with ktor - not under "mysite.com/static/..."
我通读了 Serving Static Content 并且遇到了脑梗。
我有一个文件夹 /resources/static
。它里面有静态的东西。其中一些内容是 index.html、favicon.ico、css 文件夹、js 文件夹等
我希望它显示为 https://example.org/favicon.ico, https://example.org/(默认为 index.html)等
文档中的所有示例均针对显示为 https://example.org/static/index.html
的网站
我不明白“静态”、“资源”、“资源”、“文件”之间的区别
routing {
static("static") {
files("css")
files("js")
file("image.png")
file("random.txt", "image.png")
default("index.html")
}
}
这可能做到了。
static("/") {
resources(resourcePackage = "static")
}
defaultResource(resource = "index.html", resourcePackage = "static")
static("static") - 这是说当客户端请求 [your_host]/static 然后使用静态处理程序来处理请求。
每个配置的处理程序将按顺序 运行 直到第一个匹配,因此如果 css 目录下没有文件与请求匹配,那么下一个将 运行.
files("css") - 这告诉静态处理程序在本地查找名为 css 的文件夹以提供静态内容(即客户端要求 [your_host] /static/style.css 将得到 [app_directory]/css/style.css
file("image.png") - 这告诉静态处理程序 return 本地文件来提供静态内容(即客户端要求 [your_host]/static/ * 将得到 [app_directory]/image.png
default("index.html") - 这将为任何请求 [your_host]/static/*[ 提供本地文件 [app_directory]/index.html =10=]
resource、resources 和 defaultResource 做同样的事情,但针对的是应用程序内置的资源,而不是文件系统上的资源。
我通读了 Serving Static Content 并且遇到了脑梗。
我有一个文件夹 /resources/static
。它里面有静态的东西。其中一些内容是 index.html、favicon.ico、css 文件夹、js 文件夹等
我希望它显示为 https://example.org/favicon.ico, https://example.org/(默认为 index.html)等
文档中的所有示例均针对显示为 https://example.org/static/index.html
的网站我不明白“静态”、“资源”、“资源”、“文件”之间的区别
routing {
static("static") {
files("css")
files("js")
file("image.png")
file("random.txt", "image.png")
default("index.html")
}
}
这可能做到了。
static("/") {
resources(resourcePackage = "static")
}
defaultResource(resource = "index.html", resourcePackage = "static")
static("static") - 这是说当客户端请求 [your_host]/static 然后使用静态处理程序来处理请求。 每个配置的处理程序将按顺序 运行 直到第一个匹配,因此如果 css 目录下没有文件与请求匹配,那么下一个将 运行.
files("css") - 这告诉静态处理程序在本地查找名为 css 的文件夹以提供静态内容(即客户端要求 [your_host] /static/style.css 将得到 [app_directory]/css/style.css
file("image.png") - 这告诉静态处理程序 return 本地文件来提供静态内容(即客户端要求 [your_host]/static/ * 将得到 [app_directory]/image.png
default("index.html") - 这将为任何请求 [your_host]/static/*[ 提供本地文件 [app_directory]/index.html =10=]
resource、resources 和 defaultResource 做同样的事情,但针对的是应用程序内置的资源,而不是文件系统上的资源。