1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.util.web.*
8 * [Page] implementation that delivers static files from the filesystem.
10 class ReloadingPage<R : Request> @Inject constructor(private val prefix: String, private val path: String, private val mimeType: String) : Page<R> {
12 override fun isPrefixPage() = true
14 override fun getPath() = prefix
16 override fun handleRequest(request: R, response: Response): Response {
17 val filename = request.uri.path.split("/").last()
18 File(path, filename).also { file ->
20 response.content.use { output ->
21 file.forEachBlock { buffer, bytesRead ->
22 output.write(buffer, 0, bytesRead)
25 response.statusCode = 200
26 response.contentType = mimeType
28 response.statusCode = 404
29 response.statusText = "Not found"