Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
支持配置服务目录
Browse files Browse the repository at this point in the history
  • Loading branch information
asforest committed Nov 16, 2022
1 parent f2c9e6e commit 6d52a5b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ tasks.withType<ShadowJar> {
attributes("Main-Class" to "MiniHttpServer")
}

// 打包源代码
sourceSets.main.get().allSource.sourceDirectories.map {
from(it) {into("sources/"+it.name) }
}

archiveClassifier.set("")
}
2 changes: 2 additions & 0 deletions src/main/kotlin/AppConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
data class AppConfig(
val port: Int,
val serve: String,
val home: String,
val certificateFile: String,
val certificatePass: String,
)
9 changes: 4 additions & 5 deletions src/main/kotlin/MiniHttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ class MiniHttpServer

config = AppConfig(
port = configYaml["port"]?.run { this as Int } ?: 8850,
serve = configYaml["serve"]?.run { this as String } ?: "public",
home = configYaml["home"]?.run { this as String } ?: "404.html",
certificateFile = configYaml["jks-certificate-file"]?.run { this as String } ?: "",
certificatePass = configYaml["jks-certificate-pass"]?.run { this as String } ?: "",
)
} catch (e: YAMLException) {
exitWithError("配置文件读取出错(格式不正确),可能的位置和原因: ${e.cause?.message}")
}

val publidDir = File(workdir, "public")

if (!(File(publidDir, "current-version.txt")).exists())
exitWithError("找不到public/current-version.txt,启动失败,请检查此文件是否存在")
val publidDir = File(workdir, config.serve)

try {
server = Server(publidDir, config.port)
Expand All @@ -68,7 +67,7 @@ class MiniHttpServer
server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false)

println("Listening on: ${config.port}")
println("API地址: http://localhost:${config.port}/current-version.txt")
println("API地址: http://localhost:${config.port}")

println()
println("使用提示1:显示的所有报错信息都不用管,直接忽略就好!")
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 修改监听端口
port: 1800
port: 6600

# 服务目录
serve: public

# 加载jks格式证书文件,默认请留空
jks-certificate-file:
Expand Down

0 comments on commit 6d52a5b

Please sign in to comment.