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

Commit 6d52a5b

Browse files
committed
支持配置服务目录
1 parent f2c9e6e commit 6d52a5b

6 files changed

Lines changed: 22 additions & 6 deletions

File tree

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ tasks.withType<ShadowJar> {
3737
attributes("Main-Class" to "MiniHttpServer")
3838
}
3939

40+
// 打包源代码
41+
sourceSets.main.get().allSource.sourceDirectories.map {
42+
from(it) {into("sources/"+it.name) }
43+
}
44+
4045
archiveClassifier.set("")
4146
}

src/main/kotlin/AppConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
data class AppConfig(
22
val port: Int,
3+
val serve: String,
4+
val home: String,
35
val certificateFile: String,
46
val certificatePass: String,
57
)

src/main/kotlin/MiniHttpServer.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ class MiniHttpServer
4444

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

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

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

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

7372
println()
7473
println("使用提示1:显示的所有报错信息都不用管,直接忽略就好!")

src/main/resources/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 修改监听端口
2-
port: 1800
2+
port: 6600
3+
4+
# 服务目录
5+
serve: public
36

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

0 commit comments

Comments
 (0)