From 128a487afbf1c508d3cadd97dfb6f325c7d2896d Mon Sep 17 00:00:00 2001 From: SOR <3272194354@qq.com> Date: Fri, 9 Oct 2026 19:54:07 +0800 Subject: [PATCH] path of modules, README_en --- README.md | 4 + README_en.md | 97 +++++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/resources/application-example.yaml | 2 +- 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 README_en.md diff --git a/README.md b/README.md index 4a2f141..9ac5be2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Ktor Server Demo +[English](./README_en.md) / 简体中文 + +--- + Ktor 3.x 后端项目,采用纯正、原生的 Ktor 方式(Idiomatic Ktor)完全重构实现,与 `Springboot4-Vue3` 项目功能与数据结构对齐,支持 Vue 3 前端无缝对接。 --- diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000..5483e4c --- /dev/null +++ b/README_en.md @@ -0,0 +1,97 @@ +# Ktor Server Demo + +English / [简体中文](./README.md) + +--- + +A Ktor 3.x backend project rewritten in an idiomatic Ktor manner, fully aligned with the features and data schemas of `Springboot4-Vue3`, providing seamless support for the Vue 3 frontend. + +--- + +## Tech Stack + +- **Language & Build**: Kotlin (`jvmToolchain(21)` / `25`) + Gradle (Kotlin DSL) +- **Web Framework**: Ktor 3.6.0 (Engine: CIO) +- **Database & ORM**: + - MySQL 8+ (`mysql-connector-j:9.2.0`) + - HikariCP Connection Pool (`5.1.0`) + - JetBrains Exposed ORM (`0.55.0`, including Core, JDBC, DAO, and `exposed-kotlin-datetime`) +- **Cache & Rate Limiting**: Redis 6+ + Lettuce Client (`6.3.2.RELEASE`) +- **Message Queue**: RabbitMQ 3.8+ (`amqp-client:5.34.0`) +- **Mail Service**: Jakarta Mail (`org.eclipse.angus:jakarta.mail:2.0.4`) +- **Authentication & Encryption**: + - Auth0 Java-JWT (`4.4.0`) + Ktor Auth JWT (`ktor-server-auth-jwt`) + - BCrypt Password Hashing (`at.favre.lib:bcrypt:0.10.2`, 100% compatible with Spring Security BCrypt) +- **Serialization & Datetime**: `kotlinx-serialization-json` + `kotlinx-datetime` +- **Real-time Communication**: Ktor WebSockets (`ktor-server-websockets`) +- **CORS & Error Handling**: Ktor CORS (`ktor-server-cors`) + StatusPages (`ktor-server-status-pages`) + +--- + +## Prerequisites + +- JDK 21+ (JDK 21 or JDK 25 recommended) +- MySQL 8.0+ +- Redis 6.0+ +- RabbitMQ 3.8+ + +--- + +## Quick Start + +### 1. Initialize Database + +Import the included database schema and sample data: + +```bash +mysql -u backend -p kotlin_springboot < src/main/resources/springboot_vue3.sql +``` + +> **Default Test Account**: +> - Username: `test` +> - Password: `123456` +> - Email: `1234567890@gmail.com` + +### 2. Configure Application Properties + +Review and edit `src/main/resources/application.yaml` (or refer to `application-example.yaml`): + +- **datasource**: JDBC database URL, username, and password +- **redis**: Redis connection URL (default: `redis://localhost:6379`) +- **rabbitmq**: RabbitMQ credentials and queue name (default queue: `mail`) +- **mail**: SMTP account and authorization code +- **jwt**: JWT secret key and expiration hours + +### 3. Build & Run + +Run Gradle tasks in the project root directory: + +```bash +# Build project +./gradlew build + +# Run server +./gradlew run +``` + +Upon successful startup, the server listens and logs: +```text +INFO Application - Responding at http://0.0.0.0:8080 +``` + +--- + +## API Endpoints + +| Method | Path | Authentication | Description | +|:-------|:------------------------------------------------|:---------------|:--------------------------------------------------------------------| +| `POST` | `/api/v1/auth/login` or `/api/auth/login` | Public | Login via username/email and password, returns Token and expiration | +| `GET` | `/api/v1/auth/ask-code` or `/api/auth/ask-code` | Public | Send email verification code (`?email=...&type=register`) | +| `POST` | `/api/v1/auth/register` or `/api/auth/register` | Public | Register a new account via email | +| `POST` | `/api/v1/auth/reset` or `/api/auth/reset` | Public | Reset password with verification code | +| `GET` | `/api/v1/auth/logout` or `/api/auth/logout` | `Bearer Token` | Invalidate token and add to Redis blacklist | +| `GET` | `/api/v1/auth/relogin` or `/api/auth/relogin` | `Bearer Token` | Refresh and renew JWT token | +| `GET` | `/api/test/hello` | Public | Health and connectivity test | +| `GET` | `/api/test/wstoken` | Public | Issue a one-time handshake token for WebSocket | +| `WS` | `/ws/test` | Public | Test WebSocket echo pipeline | +| `WS` | `/ws/v1/example` | `?token=...` | Establish WebSocket connection with one-time token verification | diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df6a6ad..9b7cb4a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip networkTimeout=10000 retries=0 retryBackOffMs=500 diff --git a/src/main/resources/application-example.yaml b/src/main/resources/application-example.yaml index ae14b08..8d88488 100644 --- a/src/main/resources/application-example.yaml +++ b/src/main/resources/application-example.yaml @@ -3,7 +3,7 @@ ktor: port: 8080 application: modules: - - io.github.sor2171.ApplicationKt.module + - io.github.sor2171.backend.ApplicationKt.module datasource: url: "jdbc:mysql://localhost:3306/kotlin_springboot?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"