Skip to content

Commit

Permalink
chore: fix wrong route for api/v1/genhtml
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk committed Oct 29, 2024
1 parent 83f54fb commit 0a5304c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.pdfgen.application.api.pdf

import com.fasterxml.jackson.databind.JsonNode
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand All @@ -13,36 +12,32 @@ import no.nav.pdfgen.logger

fun Route.registerGenerateHtmlApi(env: Environment = Environment()) {
if (env.enableHtmlEndpoint) {
route("/api/v1/genhtml") {
if (!env.disablePdfGet) {
get("/{applicationName}/{template}") {
val template = call.parameters["template"]!!
val applicationName = call.parameters["applicationName"]!!
createHtmlFromTemplateData(template, applicationName)?.let { call.respond(it) }
?: call.respondText(
"Template or application not found",
status = HttpStatusCode.NotFound
)
}
}

post("/{applicationName}/{template}") {
val startTime = System.currentTimeMillis()
if (!env.disablePdfGet) {
get("/{applicationName}/{template}") {
val template = call.parameters["template"]!!
val applicationName = call.parameters["applicationName"]!!
val jsonNode: JsonNode = call.receive()

createHtml(template, applicationName, jsonNode)?.let {
call.respond(it)
logger.info(
"Done generating HTML in ${System.currentTimeMillis() - startTime}ms"
)
}
createHtmlFromTemplateData(template, applicationName)?.let { call.respond(it) }
?: call.respondText(
"Template or application not found",
status = HttpStatusCode.NotFound
)
}
}

post("/{applicationName}/{template}") {
val startTime = System.currentTimeMillis()
val template = call.parameters["template"]!!
val applicationName = call.parameters["applicationName"]!!
val jsonNode: JsonNode = call.receive()

createHtml(template, applicationName, jsonNode)?.let {
call.respond(it)
logger.info("Done generating HTML in ${System.currentTimeMillis() - startTime}ms")
}
?: call.respondText(
"Template or application not found",
status = HttpStatusCode.NotFound
)
}
}
}
4 changes: 1 addition & 3 deletions src/main/kotlin/no/nav/pdfgen/plugins/LifecycleHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import no.nav.pdfgen.ApplicationState

fun Application.configureLifecycleHooks(applicationState: ApplicationState) {

monitor.subscribe(ApplicationStarted) {
applicationState.ready = true
}
monitor.subscribe(ApplicationStarted) { applicationState.ready = true }
monitor.subscribe(ApplicationStopped) {
applicationState.ready = false
applicationState.alive = false
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/no/nav/pdfgen/plugins/StatusPages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.ktor.server.application.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import no.nav.pdfgen.ApplicationState
import no.nav.pdfgen.logger

fun Application.configureStatusPages(
Expand Down

0 comments on commit 0a5304c

Please sign in to comment.