Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Last active January 24, 2022 18:48
Show Gist options
  • Save oharaandrew314/f34c2c06ba350a101490e58f006f4ff0 to your computer and use it in GitHub Desktop.
Save oharaandrew314/f34c2c06ba350a101490e58f006f4ff0 to your computer and use it in GitHub Desktop.
fun main() {
val imagesHost = System.getenv("IMAGES_HOST")
val imagesApiKey = System.getenv("IMAGES_API_KEY")
val dbHost = System.getenv("DB_HOST")
val dbUser = System.getenv("DB_USER")
val dbPass = System.getenv("DB_PASS")
val dbName = System.getenv("DB_NAME")
val dataSource = MysqlDataSource().apply {
databaseName = dbName
serverName = dbHost
user = dbUser
password = dbPass
}
val imagesBackend = ClientFilters.SetHostFrom(Uri.of(imagesHost))
.then(ClientFilters.BearerAuth(imagesApiKey))
.then(JavaHttpClient())
val petService = PetService(
pets = PetsDao(dataSource),
images = ThirdPartyImageClient(imagesBackend)
)
RestApi(petService)
.toHttpHandler()
.asServer(SunHttp(port = 8000))
.start()
.block()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment