Hello, I have a problem. In the code below, I try ...
# server
b
Hello, I have a problem. In the code below, I try to set up a static directory. Unfortunately, I ran into a 404 error. I looked at the WIKI example, but nothing improved.
p
Based on the log, your config assumes that
static("assets")
combined with the nested
resources("css")
exposes
/assets/css
as the resource access path from which
ollie.css
will be obtained. What it is is actually saying is, when you want to access a resource under
/assets
such as
/assets/ollie.css
, search for
ollie.css
inside of each of the following resources directories.
Copy code
static/css
static/imgs
static/js
static/scss
static/vendors
Whereas your
ollie.js
is in
static/assets/css
It's worth looking at the specific example given in https://github.com/ktorio/ktor-documentation/tree/main/codeSnippets/snippets/static-resources It provides a direct example of this config, including the files in their applicable resource directories. If you want to update the config instead of restructuring your files, depends on how much freedom to access resources you want to permit. If you must restrict so only content from the
js
,
css
,
imgs
,
scss
&
vendors
(and sub-dirs of them) will be served, then you will need to split it out into more
static()
calls. Example
Copy code
routing {
    static("/") {
        staticBasePackage = "static"
        resource("index.html")
        defaultResource("index.html")
        static("assets/css") {
            resources("assets/css")
        }
        static("assets/js") {
            resources("assets/js")
        }
    }
}
If your ok to serve all directories and sub-dirs in
static/assets
, including say fictional
static/assets/other
that isn't specifically in the config right now, then you can retain much of your current config. Example
Copy code
routing {
    static("/") {
        staticBasePackage = "static"
        resource("index.html")
        defaultResource("index.html")
        static("assets") {
            staticBasePackage = "static/assets"
            resources(".")
        }
    }
}
b
Thank you