Skip to content

Commit 2267caa

Browse files
committed
Fiks serve static på "/"
1 parent 0dd3020 commit 2267caa

File tree

1 file changed

+13
-4
lines changed
  • backend/src/main/kotlin/no/nais/cloud/testnais/sandbox/bachelorurlforkorter

1 file changed

+13
-4
lines changed

backend/src/main/kotlin/no/nais/cloud/testnais/sandbox/bachelorurlforkorter/UrlForkorterApi.kt

+13-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ fun startAppServer(config: Config) {
3232
post("forkort", UrlForkorterController::forkort, Rolle.Alle)
3333
get("hentalle", UrlForkorterController::hentAlleMedMetadata, Rolle.Alle)
3434
}
35-
get("/") { ctx -> ctx.redirect("/index.html") }
36-
get("{korturl}", UrlForkorterController::redirect, Rolle.Alle)
35+
get("{korturl}") { ctx ->
36+
if (ctx.pathParam("korturl") == "index.html") {
37+
val asset =
38+
UrlForkorterController::class.java.getResourceAsStream("/public/index.html")
39+
if (asset != null) {
40+
ctx.contentType("text/html").result(asset)
41+
}
42+
} else {
43+
UrlForkorterController.redirect(ctx)
44+
}
45+
}
3746
}
3847
// TODO: Kun for lokal utvikling med hot reload
39-
javalinConfig.bundledPlugins.enableCors {cors ->
40-
cors.addRule {it.allowHost("http://localhost:5173")}
48+
javalinConfig.bundledPlugins.enableCors { cors ->
49+
cors.addRule { it.allowHost("http://localhost:5173") }
4150
}
4251
}
4352

0 commit comments

Comments
 (0)