Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/com/londogard/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.ktor.server.plugins.hsts.*
import io.ktor.server.plugins.httpsredirect.*
import io.ktor.server.plugins.partialcontent.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
Expand Down Expand Up @@ -65,7 +66,8 @@ fun Application.module() {

// Default: [Accept, AcceptLanguages, ContentLanguage, ContentType]
install(CORS) {
anyHost()
//anyHost()
allowHost("*.londogard.com", schemes = listOf("https"))
allowMethod(HttpMethod.Options)
allowHeader("Authorization")
allowNonSimpleContentTypes = true
Expand Down Expand Up @@ -151,7 +153,10 @@ fun Application.module() {
}

install(CachingHeaders) {
options { _, outgoingContent ->
options { call, outgoingContent ->
if ("easyindex" in call.request.uri) {
return@options CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 5 * 60), ZonedDateTime.now().plusMinutes(5))
}
when (outgoingContent.contentType?.withoutParameters()) {
ContentType.Text.CSS -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60), ZonedDateTime.now().plusDays(1))
ContentType.Application.Rss -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60), ZonedDateTime.now().plusDays(1))
Expand Down
23 changes: 20 additions & 3 deletions src/com/londogard/api/ApiRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ import com.londogard.summarizer.SummarizeReq
import com.londogard.summarizer.summarize
import com.londogard.textgen.LanguageModelHelper
import com.londogard.textgen.TextGenInput
import io.ktor.server.application.call
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.server.auth.authenticate
import io.ktor.http.*
import io.ktor.server.request.receive
import io.ktor.server.request.receiveOrNull
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.plugins.cachingheaders.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.coroutines.Dispatchers
Expand All @@ -43,6 +48,18 @@ fun Route.apiRoute(redirections: MutableMap<String, String>): Route = route("/ap
call.respond(splitBills(payments))
}

route("/easyindex") {
get("/{ticker}") {
val ticker = call.parameters["ticker"] ?: throw InvalidRouteException()
val yahoo = HttpClient(CIO)
.use { client ->
client.get("https://query1.finance.yahoo.com/v7/finance/quote?symbols=$ticker").bodyAsText()
}

call.respond(resultResponse(yahoo))
}
}

/**
* POST: /api/url
* {url: string} --> {result: string} (result is the hash)
Expand Down