Skip to content

Commit cc34f9b

Browse files
committed
Add REST Server startup by default to convex peer start
1 parent 877c71d commit cc34f9b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

convex-cli/src/main/java/convex/cli/peer/PeerStart.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import convex.peer.API;
1818
import convex.peer.ConfigException;
1919
import convex.peer.Server;
20+
import convex.restapi.RESTServer;
2021
import etch.EtchStore;
2122
import picocli.CommandLine.Command;
2223
import picocli.CommandLine.Mixin;
@@ -57,6 +58,14 @@ public class PeerStart extends APeerCommand {
5758

5859
@Option(names = { "--url" }, description = "URL for the peer to publish. If not provided, the peer will have no public URL.")
5960
private String url;
61+
62+
@Option(names = { "--norest" }, description = "Disable REST srever.")
63+
private boolean norest;
64+
65+
@Option(names = { "--api-port" }, description = "Port for REST API.")
66+
private Integer apiport;
67+
68+
6069

6170
// @Option(names = { "-b",
6271
// "--bind-address" }, description = "Bind address of the network interface. Defaults to local loop back device for %n"
@@ -121,12 +130,18 @@ public void run() {
121130

122131
}
123132

133+
RESTServer restServer=null;;
124134
try {
125135
HashMap<Keyword,Object> config=new HashMap<>();
126136
config.put(Keywords.KEYPAIR, peerKey);
127137
config.put(Keywords.STORE, store);
128-
Server s=API.launchPeer(config);
129-
while (s.isRunning()&&!Thread.currentThread().isInterrupted()) {
138+
Server server=API.launchPeer(config);
139+
140+
restServer=RESTServer.create(server);
141+
restServer.start(apiport);
142+
143+
144+
while (server.isRunning()&&!Thread.currentThread().isInterrupted()) {
130145
Thread.sleep(400);
131146
}
132147
informSuccess("Peer shutdown completed");
@@ -135,6 +150,8 @@ public void run() {
135150
} catch (InterruptedException e) {
136151
informWarning("Peer interrupted before normal shutdown");
137152
return;
153+
} finally {
154+
if (restServer!=null) restServer.stop();
138155
}
139156
}
140157
}

0 commit comments

Comments
 (0)