-
-
Save alexdlaird/522cba505b0a9f935f65036355c46f4a to your computer and use it in GitHub Desktop.
HTTP server integration example for java-ngrok, full documentation found at https://javadoc.io/doc/com.github.alexdlaird/java-ngrok/latest/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.alexdlaird; | |
import com.github.alexdlaird.ngrok.NgrokClient; | |
import com.github.alexdlaird.ngrok.protocol.CreateTunnel; | |
import com.github.alexdlaird.ngrok.protocol.Tunnel; | |
import com.sun.net.httpserver.HttpServer; | |
import java.net.InetSocketAddress; | |
import java.util.logging.Logger; | |
public class NgrokHttpServer { | |
private static final Logger LOGGER = Logger.getLogger(String.valueOf(NgrokHttpServer.class)); | |
public static void main(String[] args) throws Exception { | |
final int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "80")); | |
final HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); | |
final NgrokClient ngrokClient = new NgrokClient.Builder().build(); | |
final CreateTunnel createTunnel = new CreateTunnel.Builder() | |
.withAddr(port) | |
.build(); | |
final Tunnel tunnel = ngrokClient.connect(createTunnel); | |
LOGGER.info(String.format("ngrok tunnel \"%s\" -> \"http://127.0.0.1:%d\"", tunnel.getPublicUrl(), port)); | |
server.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment