Skip to content

Commit

Permalink
Add REST Server startup by default to convex peer start
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 22, 2024
1 parent 877c71d commit cc34f9b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions convex-cli/src/main/java/convex/cli/peer/PeerStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import convex.peer.API;
import convex.peer.ConfigException;
import convex.peer.Server;
import convex.restapi.RESTServer;
import etch.EtchStore;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
Expand Down Expand Up @@ -57,6 +58,14 @@ public class PeerStart extends APeerCommand {

@Option(names = { "--url" }, description = "URL for the peer to publish. If not provided, the peer will have no public URL.")
private String url;

@Option(names = { "--norest" }, description = "Disable REST srever.")
private boolean norest;

@Option(names = { "--api-port" }, description = "Port for REST API.")
private Integer apiport;



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

}

RESTServer restServer=null;;
try {
HashMap<Keyword,Object> config=new HashMap<>();
config.put(Keywords.KEYPAIR, peerKey);
config.put(Keywords.STORE, store);
Server s=API.launchPeer(config);
while (s.isRunning()&&!Thread.currentThread().isInterrupted()) {
Server server=API.launchPeer(config);

restServer=RESTServer.create(server);
restServer.start(apiport);


while (server.isRunning()&&!Thread.currentThread().isInterrupted()) {
Thread.sleep(400);
}
informSuccess("Peer shutdown completed");
Expand All @@ -135,6 +150,8 @@ public void run() {
} catch (InterruptedException e) {
informWarning("Peer interrupted before normal shutdown");
return;
} finally {
if (restServer!=null) restServer.stop();
}
}
}
Expand Down

0 comments on commit cc34f9b

Please sign in to comment.