diff --git a/src/com/londogard/Main.kt b/src/com/londogard/Main.kt index c1573cc..7657950 100644 --- a/src/com/londogard/Main.kt +++ b/src/com/londogard/Main.kt @@ -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.* @@ -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 @@ -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)) diff --git a/src/com/londogard/api/ApiRoute.kt b/src/com/londogard/api/ApiRoute.kt index e9c44ef..451c1a5 100644 --- a/src/com/londogard/api/ApiRoute.kt +++ b/src/com/londogard/api/ApiRoute.kt @@ -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 @@ -43,6 +48,18 @@ fun Route.apiRoute(redirections: MutableMap): 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)