-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
574 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
SharedCode/src/jsMain/kotlin/com/surrus/galwaybus/common/DbDriver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.surrus.galwaybus.common | ||
|
||
import com.surrus.galwaybus.db.MyDatabase | ||
|
||
|
||
|
||
actual fun createDb(): MyDatabase? { | ||
return null | ||
} |
5 changes: 5 additions & 0 deletions
5
SharedCode/src/jsMain/kotlin/com/surrus/galwaybus/common/Dispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.surrus.galwaybus.common | ||
|
||
import kotlinx.coroutines.* | ||
|
||
internal actual val ApplicationDispatcher: CoroutineDispatcher = Dispatchers.Default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 46 additions & 39 deletions
85
backend/src/main/java/com/surrus/galwaybus/backend/GalwayBusServerApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,68 @@ | ||
package com.surrus.galwaybus.backend | ||
|
||
|
||
|
||
import com.surrus.galwaybus.common.model.BusStop | ||
import com.surrus.galwaybus.common.remote.GalwayBusApi | ||
import io.ktor.application.* | ||
import io.ktor.features.* | ||
import freemarker.cache.ClassTemplateLoader | ||
import io.ktor.application.Application | ||
import io.ktor.application.call | ||
import io.ktor.application.install | ||
import io.ktor.features.CallLogging | ||
import io.ktor.features.Compression | ||
import io.ktor.features.ConditionalHeaders | ||
import io.ktor.features.ContentNegotiation | ||
import io.ktor.features.DefaultHeaders | ||
import io.ktor.features.PartialContent | ||
import io.ktor.features.StatusPages | ||
import io.ktor.freemarker.FreeMarker | ||
import io.ktor.gson.gson | ||
import io.ktor.html.* | ||
import io.ktor.html.respondHtml | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.locations.KtorExperimentalLocationsAPI | ||
import io.ktor.locations.Locations | ||
import io.ktor.response.respond | ||
import io.ktor.routing.* | ||
import io.ktor.server.engine.embeddedServer | ||
import io.ktor.server.netty.Netty | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.html.* | ||
|
||
// Entry Point of the application as defined in resources/application.conf. | ||
// @see https://ktor.io/servers/configuration.html#hocon-file | ||
import io.ktor.routing.Routing | ||
import io.ktor.routing.get | ||
import io.ktor.routing.routing | ||
import io.ktor.util.error | ||
import kotlinx.html.body | ||
import kotlinx.html.head | ||
import kotlinx.html.p | ||
import kotlinx.html.title | ||
import org.example.kotlin.multiplatform.backend.serializable | ||
|
||
fun Application.main() { | ||
// This adds Date and Server headers to each response, and allows custom additional headers | ||
|
||
install(DefaultHeaders) | ||
// This uses use the logger to log every call (request/response) | ||
install(CallLogging) | ||
// install(ConditionalHeaders) | ||
// install(PartialContent) | ||
// install(Compression) | ||
// //install(Locations) | ||
// install(StatusPages) { | ||
// exception<Throwable> { cause -> | ||
// environment.log.error(cause) | ||
// call.respond(HttpStatusCode.InternalServerError) | ||
// } | ||
// } | ||
|
||
install(ContentNegotiation) { | ||
//serializable { } | ||
gson { | ||
setPrettyPrinting() | ||
} | ||
} | ||
|
||
//val busStop = BusStop(1, "name", "irish name") | ||
|
||
routing { | ||
// Here we use a DSL for building HTML on the route "/" | ||
// @see https://github.com/Kotlin/kotlinx.html | ||
get("/") { | ||
call.respondHtml { | ||
head { | ||
title { +"Ktor on Google App Engine Standard" } | ||
} | ||
body { | ||
p { | ||
+"hi there! This is Ktor running on Google Appengine Standard" | ||
} | ||
} | ||
} | ||
} | ||
get("/bus") { | ||
install(FreeMarker) { | ||
templateLoader = ClassTemplateLoader(javaClass.classLoader, "") | ||
} | ||
|
||
install(Routing) { | ||
index() | ||
|
||
get("/stops.json") { | ||
val galwayBusApi = GalwayBusApi() | ||
val busStops = galwayBusApi.fetchBusStops() | ||
call.respond(busStops) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
embeddedServer(Netty, port = 8090) { main() }.start(wait = true) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/surrus/galwaybus/backend/IndexRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.surrus.galwaybus.backend | ||
|
||
import io.ktor.http.ContentType | ||
import io.ktor.http.content.defaultResource | ||
import io.ktor.http.content.resource | ||
import io.ktor.http.content.static | ||
import io.ktor.routing.Route | ||
import io.ktor.routing.accept | ||
|
||
fun Route.index() { | ||
static("frontend") { | ||
resource("web.bundle.js") | ||
} | ||
|
||
accept(ContentType.Text.Html) { | ||
defaultResource("index.html") | ||
} | ||
} |
Oops, something went wrong.