Skip to content

Commit

Permalink
可在启动参数中设置端口号
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuo894 committed Sep 8, 2024
1 parent 4b22cc0 commit c910fde
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
6 changes: 4 additions & 2 deletions docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

### 启动

下载最新的 ani-rss-jar-with-dependencies.jar [链接](https://github.com/wushuo894/ani-rss/releases/latest)
下载最新的 **ani-rss-jar-with-dependencies.jar** [链接](https://github.com/wushuo894/ani-rss/releases/latest)

java -jar ./ani-rss-jar-with-dependencies.jar
java -jar ./ani-rss-jar-with-dependencies.jar --port 7789

通过 **http://[ip]:7789** 访问

<a href="docs">使用文档</a>
|
Expand Down
2 changes: 1 addition & 1 deletion docs/update.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
优化鉴权系统
可在启动参数中设置端口号
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ani.rss</groupId>
<artifactId>ani-rss</artifactId>
<version>1.0.87</version>
<version>1.0.88</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ani/rss/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void main(String[] args) {
try {
ConfigUtil.load();
AniUtil.load();
ThreadUtil.execute(() -> ServerUtil.create().start());
ThreadUtil.execute(() -> ServerUtil.create(args).start());
TaskUtil.start();
String version = MavenUtil.getVersion();
log.info("version {}", version);
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/ani/rss/util/ServerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,36 @@
import ani.rss.annotation.Path;
import ani.rss.auth.util.AuthUtil;
import ani.rss.entity.Result;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.http.server.HttpServerResponse;
import cn.hutool.http.server.SimpleServer;
import cn.hutool.log.Log;

import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;

public class ServerUtil {
public static final ThreadLocal<HttpServerRequest> REQUEST = new ThreadLocal<>();
public static final ThreadLocal<HttpServerResponse> RESPONSE = new ThreadLocal<>();

public static SimpleServer create() {
public static SimpleServer create(String... args) {
Map<String, String> env = System.getenv();
String port = env.getOrDefault("PORT", "7789");

args = ObjectUtil.defaultIfNull(args, new String[]{});
for (List<String> strings : CollUtil.split(Arrays.asList(args), 2)) {
String k = strings.get(0);
String v = strings.get(1);
if (k.equals("--port")) {
port = v;
}
}

SimpleServer server = HttpUtil.createServer(Integer.parseInt(port));

server.addAction("/", new RootAction());
Expand Down

0 comments on commit c910fde

Please sign in to comment.