diff options
-rw-r--r-- | build-src/src/main/kotlin/ledger-globals.gradle.kts | 2 | ||||
-rw-r--r-- | server/aio/build.gradle.kts | 19 | ||||
-rw-r--r-- | server/aio/src/main/kotlin/moe/nea/ledger/server/aio/AIO.kt | 20 | ||||
-rw-r--r-- | server/core/build.gradle.kts | 18 | ||||
-rw-r--r-- | server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt | 14 | ||||
-rw-r--r-- | server/frontend/build.gradle.kts | 16 | ||||
-rw-r--r-- | server/frontend/package.json | 10 | ||||
-rw-r--r-- | server/frontend/src/App.tsx | 14 | ||||
-rw-r--r-- | server/frontend/src/Test.tsx | 48 | ||||
-rw-r--r-- | server/frontend/src/api-schema.d.ts | 154 | ||||
-rw-r--r-- | server/frontend/src/api.ts | 4 | ||||
-rw-r--r-- | server/frontend/src/index.tsx | 20 | ||||
-rw-r--r-- | server/swagger/build.gradle.kts | 1 | ||||
-rw-r--r-- | settings.gradle.kts | 2 |
14 files changed, 215 insertions, 127 deletions
diff --git a/build-src/src/main/kotlin/ledger-globals.gradle.kts b/build-src/src/main/kotlin/ledger-globals.gradle.kts index 8d49379..4238322 100644 --- a/build-src/src/main/kotlin/ledger-globals.gradle.kts +++ b/build-src/src/main/kotlin/ledger-globals.gradle.kts @@ -1,3 +1,5 @@ +apply(plugin = "org.gradle.base") + repositories { mavenCentral() maven("https://repo.nea.moe/releases/") diff --git a/server/aio/build.gradle.kts b/server/aio/build.gradle.kts new file mode 100644 index 0000000..22819f0 --- /dev/null +++ b/server/aio/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + kotlin("jvm") + application +} + +dependencies { + declareKtorVersion() + implementation(project(":server:core")) + implementation(project(":server:frontend")) +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} + +application { + mainClass.set("moe.nea.ledger.server.core.ApplicationKt") +} + diff --git a/server/aio/src/main/kotlin/moe/nea/ledger/server/aio/AIO.kt b/server/aio/src/main/kotlin/moe/nea/ledger/server/aio/AIO.kt new file mode 100644 index 0000000..e59301f --- /dev/null +++ b/server/aio/src/main/kotlin/moe/nea/ledger/server/aio/AIO.kt @@ -0,0 +1,20 @@ +package moe.nea.ledger.server.aio + +import io.ktor.server.application.Application +import io.ktor.server.http.content.singlePageApplication +import io.ktor.server.routing.Routing +import moe.nea.ledger.server.core.AIOProvider + + +class AIO : AIOProvider { + override fun Routing.installExtraRouting() { + singlePageApplication { + useResources = true + filesPath = "ledger-web-dist" + defaultPage = "index.html" + } + } + + override fun Application.module() { + } +}
\ No newline at end of file diff --git a/server/core/build.gradle.kts b/server/core/build.gradle.kts index ad6c80e..6300a4b 100644 --- a/server/core/build.gradle.kts +++ b/server/core/build.gradle.kts @@ -8,15 +8,15 @@ plugins { dependencies { declareKtorVersion() - implementation("io.ktor:ktor-server-netty") - implementation("io.ktor:ktor-server-status-pages") - implementation("io.ktor:ktor-server-content-negotiation") - implementation("io.ktor:ktor-serialization-kotlinx-json") - implementation("io.ktor:ktor-server-compression") - implementation("io.ktor:ktor-server-cors") - implementation("sh.ondr:kotlin-json-schema:0.1.1") - implementation(project(":database:impl")) - implementation(project(":server:swagger")) + api("io.ktor:ktor-server-netty") + api("io.ktor:ktor-server-status-pages") + api("io.ktor:ktor-server-content-negotiation") + api("io.ktor:ktor-serialization-kotlinx-json") + api("io.ktor:ktor-server-compression") + api("io.ktor:ktor-server-cors") + api("sh.ondr:kotlin-json-schema:0.1.1") + api(project(":database:impl")) + api(project(":server:swagger")) runtimeOnly("ch.qos.logback:logback-classic:1.5.16") runtimeOnly("org.xerial:sqlite-jdbc:3.45.3.0") diff --git a/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt b/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt index a177b05..23b2a6a 100644 --- a/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt +++ b/server/core/src/main/kotlin/moe/nea/ledger/server/core/Application.kt @@ -8,6 +8,7 @@ import io.ktor.server.plugins.compression.Compression import io.ktor.server.plugins.contentnegotiation.ContentNegotiation import io.ktor.server.plugins.cors.routing.CORS import io.ktor.server.response.respondRedirect +import io.ktor.server.routing.Routing import io.ktor.server.routing.get import io.ktor.server.routing.route import io.ktor.server.routing.routing @@ -27,8 +28,17 @@ fun main(args: Array<String>) { EngineMain.main(args) } +interface AIOProvider { + fun Routing.installExtraRouting() + fun Application.module() +} fun Application.module() { + val aio = runCatching { + Class.forName("moe.nea.ledger.server.aio.AIO") + .newInstance() as AIOProvider + }.getOrNull() + aio?.run { module() } install(Compression) install(Documentation) { info = Info( @@ -50,7 +60,8 @@ fun Application.module() { install(CORS) { anyHost() } - val database = Database(File(System.getProperty("ledger.databasefolder"))) + val database = Database(File(System.getProperty("ledger.databasefolder", + "/home/nea/.local/share/PrismLauncher/instances/Skyblock/.minecraft/money-ledger"))) database.loadAndUpgrade() routing { route("/api") { @@ -64,6 +75,7 @@ fun Application.module() { route("/openapi") { openApiUi("/api.json") } + aio?.run { installExtraRouting() } } } diff --git a/server/frontend/build.gradle.kts b/server/frontend/build.gradle.kts new file mode 100644 index 0000000..71b5c27 --- /dev/null +++ b/server/frontend/build.gradle.kts @@ -0,0 +1,16 @@ +import com.github.gradle.node.pnpm.task.PnpmTask + +plugins { + id("com.github.node-gradle.node") version "7.1.0" + `java-library` +} + +val webDist by tasks.register("webDist", PnpmTask::class) { + args.addAll("build") + outputs.dir("dist") +} +tasks.jar { + from(webDist) { + into("ledger-web-dist/") + } +} diff --git a/server/frontend/package.json b/server/frontend/package.json index 83dfff6..f8a89f1 100644 --- a/server/frontend/package.json +++ b/server/frontend/package.json @@ -22,5 +22,13 @@ "@solidjs/router": "^0.15.3", "openapi-fetch": "^0.13.4", "solid-js": "^1.9.3" - } + }, + +"devEngines": { + "packageManager": { + "name": "pnpm", + "onFail": "error" + } + }, + "packageManager": "pnpm@^9.3.0" } diff --git a/server/frontend/src/App.tsx b/server/frontend/src/App.tsx index 6773d90..e35bb42 100644 --- a/server/frontend/src/App.tsx +++ b/server/frontend/src/App.tsx @@ -1,11 +1,13 @@ -import type {Component} from "solid-js"; -import {A} from "@solidjs/router"; +import type { Component } from "solid-js"; +import { A } from "@solidjs/router"; const App: Component = () => { - return <> - Hello World - <A href="/test">Test Page</A> - </>; + return ( + <> + Hello World + <A href="/test">Test Page</A> + </> + ); }; export default App; diff --git a/server/frontend/src/Test.tsx b/server/frontend/src/Test.tsx index 6eee2d6..15d2f73 100644 --- a/server/frontend/src/Test.tsx +++ b/server/frontend/src/Test.tsx @@ -1,23 +1,31 @@ -import {A, createAsync} from "@solidjs/router"; -import {client} from "./api.js"; -import {For, Suspense} from "solid-js"; +import { A, createAsync } from "@solidjs/router"; +import { client } from "./api.js"; +import { For, Suspense } from "solid-js"; export default function Test() { - let items = createAsync(() => client.GET("/item", { - params: { - query: { - itemId: ['HYPERION', 'BAT_WAND'] - } - } - })) - return <> - Test page <A href={"/"}>Back to main</A> - <hr/> - <Suspense fallback={"Loading items..."}> - <p>Here are all Items:</p> - <For each={Object.entries(items()?.data || {})}> - { ([id, name]) => <li><code>{id}</code>: {name}</li>} - </For> - </Suspense> + let items = createAsync(() => + client.GET("/item", { + params: { + query: { + itemId: ["HYPERION", "BAT_WAND"], + }, + }, + }) + ); + return ( + <> + Test page <A href={"/"}>Back to main</A> + <hr /> + <Suspense fallback={"Loading items..."}> + <p>Here are all Items:</p> + <For each={Object.entries(items()?.data || {})}> + {([id, name]) => ( + <li> + <code>{id}</code>: {name} + </li> + )} + </For> + </Suspense> </> -}
\ No newline at end of file + ); +} diff --git a/server/frontend/src/api-schema.d.ts b/server/frontend/src/api-schema.d.ts index 920cd4b..93bedc9 100644 --- a/server/frontend/src/api-schema.d.ts +++ b/server/frontend/src/api-schema.d.ts @@ -4,95 +4,95 @@ */ export interface paths { - "/profiles": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** List all profiles and players known to ledger */ - get: operations["listProfiles"]; - put?: never; - post?: never; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + "/profiles": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; }; - "/item": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** Get item names for item ids */ - get: operations["getItemNames"]; - put?: never; - post?: never; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; + /** List all profiles and players known to ledger */ + get: operations["listProfiles"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/item": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; }; + /** Get item names for item ids */ + get: operations["getItemNames"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; } export type webhooks = Record<string, never>; export interface components { - schemas: never; - responses: never; - parameters: never; - requestBodies: never; - headers: never; - pathItems: never; + schemas: never; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; } export type $defs = Record<string, never>; export interface operations { - listProfiles: { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; + listProfiles: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + 200: { + headers: { + [name: string]: unknown; }; - requestBody?: never; - responses: { - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - playerId: string; - profileId: string; - }[]; - }; - }; + content: { + "application/json": { + playerId: string; + profileId: string; + }[]; }; + }; + }; + }; + getItemNames: { + parameters: { + query?: { + itemId?: string[]; + }; + header?: never; + path?: never; + cookie?: never; }; - getItemNames: { - parameters: { - query?: { - itemId?: string[]; - }; - header?: never; - path?: never; - cookie?: never; + requestBody?: never; + responses: { + 200: { + headers: { + [name: string]: unknown; }; - requestBody?: never; - responses: { - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - [key: string]: string; - }; - }; - }; + content: { + "application/json": { + [key: string]: string; + }; }; + }; }; + }; } diff --git a/server/frontend/src/api.ts b/server/frontend/src/api.ts index 00273ec..22cf6ca 100644 --- a/server/frontend/src/api.ts +++ b/server/frontend/src/api.ts @@ -1,6 +1,6 @@ import createClient from "openapi-fetch"; -import type {paths} from "./api-schema.js"; +import type { paths } from "./api-schema.js"; const apiRoot = import.meta.env.DEV ? "//localhost:8080/api" : "/api"; -export const client = createClient<paths>({baseUrl: apiRoot});
\ No newline at end of file +export const client = createClient<paths>({ baseUrl: apiRoot }); diff --git a/server/frontend/src/index.tsx b/server/frontend/src/index.tsx index 023872c..6ab7d4e 100644 --- a/server/frontend/src/index.tsx +++ b/server/frontend/src/index.tsx @@ -1,21 +1,21 @@ /* @refresh reload */ -import {render} from "solid-js/web"; +import { render } from "solid-js/web"; import "./index.css"; -import type {RouteDefinition} from "@solidjs/router"; -import {Router} from "@solidjs/router"; -import {lazy} from "solid-js"; +import type { RouteDefinition } from "@solidjs/router"; +import { Router } from "@solidjs/router"; +import { lazy } from "solid-js"; const root = document.getElementById("root"); if (!(root instanceof HTMLElement)) { - throw new Error( - "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?" - ); + throw new Error( + "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?" + ); } const routes: Array<RouteDefinition> = [ - {path: '/', component: lazy(() => import("./App.tsx"))}, - {path: "/test/", component: lazy(() => import("./Test.tsx"))} -] + { path: "/", component: lazy(() => import("./App.tsx")) }, + { path: "/test/", component: lazy(() => import("./Test.tsx")) }, +]; render(() => <Router>{routes}</Router>, root!); diff --git a/server/swagger/build.gradle.kts b/server/swagger/build.gradle.kts index 1a578cc..76e5f78 100644 --- a/server/swagger/build.gradle.kts +++ b/server/swagger/build.gradle.kts @@ -8,7 +8,6 @@ plugins { dependencies { declareKtorVersion() api("io.ktor:ktor-server-core") - api("io.ktor:ktor-server-webjars") api("sh.ondr:kotlin-json-schema:0.1.1") implementation("org.webjars:swagger-ui:5.18.2") } diff --git a/settings.gradle.kts b/settings.gradle.kts index c730400..949cbe4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,4 +33,6 @@ include("basetypes") include("mod") include("server:swagger") include("server:core") +include("server:frontend") +include("server:aio") includeBuild("build-src") |