https://kotlinlang.org logo
#ktor
Title
r

redrield

11/17/2017, 3:56 PM
Alright, so I know that I can configure a default file to serve in a static block, but how can I serve a static file from the structure I've set in that static block for one request?
o

orangy

11/17/2017, 6:09 PM
Not sure I understand. Can you give an example?
r

redrield

11/17/2017, 6:19 PM
I found a way to do it, though I feel there's a better way.
Basically, I have a react app that gets served at /, and there's some data to be filled out that will eventually be POSTed serverside
When that happens, I want to send back a static html file saying that the request has been processed, and that just has some javascript to send them back to the root of the app after a couple of seconds
I just ended up doing this
call.respond(File(staticFolder, "success.html").readText())
o

orangy

11/17/2017, 7:06 PM
Hmm, why would you send html page in response to a React app POST request? I imagine you’d send a JSON back with data needed to render the message, and then React app would do the rest?
Also,
readText
from file is blocking call. Better to respond with LocalFileContent
I think we might need
call.respondFile(baseDir, file)
r

redrield

11/17/2017, 7:10 PM
Regardless of the poor architecture choices on my part, I thing that'd be a good addition
o

orangy

11/17/2017, 7:12 PM
Added
👍 1