How can I make it so I host the website & the ...
# ktor
d
How can I make it so I host the website & the backend in the ktor app. I was thinking of static content and then XMLHTTPRequest to access the backend api: ktor app +----------- / -> public/index.html (has assets that also need to be accessible from the /public folder) /security -> public/security.html (has assets that also need to be accessible from the /public folder) /api -> handled by the api using GET, POST, etc. functions How should my routes look? EDIT: I tried this but it didn't really work. /api returned correctly but / and /index.html or any other asset in /public did not show up.
Copy code
get("/api") {
            call.respondText("works")
        }

        static {
            resource("/", "public/index.html")
            resource("*", "public/index.html")
            resources("public")
        }
h
If you have a static website, then yes, you can just serve it as static or even use any kind of view engine. Not show up you mean how? 404?
d
@hhariri I want to serve the html with js and css in different files (all in /public) at the root of the website, then override /api and /file to be handled by get("/api") etc etc
h
That should work with a single entry for your route to resources. You don’t need to do further mappings in static.
d
Can you give me an example Route for that? I have tried many things and they don't work for me
h
These should all be correct and working https://ktor.io/docs/serving-static-content.html#folders. Shows how to also distinguish js/css. Click on the demo project at the top.
d
I have tried those already, that's the page I started at. I get 404 when trying root, domain.com/index.html etc
h
DM me a sample that doesnt work.