From a8446b6b73777a44b498c36b90f0ee27f4ddd4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amalie=20Mans=C3=A5ker?= Date: Tue, 4 Jul 2023 13:30:06 +0200 Subject: [PATCH] :bug: Konfigurert aksesskontroll mot backend Co-authored-by: Sindre Kjelsrud Co-authored-by: Markus A. R. Johansen --- backend/build.gradle.kts | 1 + .../main/kotlin/no/nav/helse/sprik/Application.kt | 2 +- .../kotlin/no/nav/helse/sprik/plugins/Routing.kt | 6 ++++++ frontend/pages/index.tsx | 14 ++++++-------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 405f9d9..48b9122 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -26,4 +26,5 @@ dependencies { implementation("ch.qos.logback:logback-classic:$logback_version") testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") + implementation("io.ktor:ktor-server-cors:$ktor_version") } \ No newline at end of file diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt b/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt index 138465a..7d149f5 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/Application.kt @@ -7,7 +7,7 @@ import no.nav.helse.sprik.plugins.* fun main() { embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = Application::module) - .start(wait = true) + .start(wait = true) } fun Application.module() { diff --git a/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt b/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt index 43dd9e2..bf3e889 100644 --- a/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt +++ b/backend/src/main/kotlin/no/nav/helse/sprik/plugins/Routing.kt @@ -1,10 +1,16 @@ package no.nav.helse.sprik.plugins +import io.ktor.http.* import io.ktor.server.routing.* import io.ktor.server.response.* import io.ktor.server.application.* +import io.ktor.server.plugins.cors.routing.* fun Application.configureRouting() { + install(CORS) { + anyHost() + allowMethod(HttpMethod.Get) + } routing { get("/") { call.respondText("Hello World!") diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 46864ca..171cc7f 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -5,21 +5,19 @@ import useSWR from "swr"; const fetcher = (url: any) => axios.get(url).then(res => res.data) -function fetching() { - const {data, error, isLoading} = useSWR('http://0.0.0.0:8080/', fetcher); - if (error) return
failed to load: {error.message}
- if (isLoading) return
Loading...
- return
{data.data}
-} - export default function Home() { + + const {data, error, isLoading} = useSWR('http://0.0.0.0:8080/', fetcher); + console.log(data); + return (
Sprik - {fetching()} + + {data ?
{data}
:
Laster
}
)