diff --git a/src/main/scala/lc/Main.scala b/src/main/scala/lc/Main.scala index c59f94b..7f60c1c 100644 --- a/src/main/scala/lc/Main.scala +++ b/src/main/scala/lc/Main.scala @@ -16,7 +16,7 @@ object LCFramework { val captcha = new Captcha(config = config, captchaProviders = captchaProviders) val backgroundTask = new BackgroundTask(config = config, captcha = captcha) backgroundTask.beginThread(delay = config.threadDelay) - val server = new Server(port = config.port, captcha = captcha) + val server = new Server(address = config.address, port = config.port, captcha = captcha) server.start() } } diff --git a/src/main/scala/lc/core/captchaFields.scala b/src/main/scala/lc/core/captchaFields.scala index 80e691d..0e41b71 100644 --- a/src/main/scala/lc/core/captchaFields.scala +++ b/src/main/scala/lc/core/captchaFields.scala @@ -19,6 +19,7 @@ object AttributesEnum extends Enumeration { val NAME: Value = Value("name") val RANDOM_SEED: Value = Value("randomSeed") val PORT: Value = Value("port") + val ADDRESS: Value = Value("address") val CAPTCHA_EXPIRY_TIME_LIMIT: Value = Value("captchaExpiryTimeLimit") val THROTTLE: Value = Value("throttle") val THREAD_DELAY: Value = Value("threadDelay") diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index 6b10612..fc1d6db 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -40,6 +40,7 @@ class Config(configFilePath: String) { private val configJson = parse(configString) val port: Int = (configJson \ AttributesEnum.PORT.toString).extract[Int] + val address: String = (configJson \ AttributesEnum.ADDRESS.toString).extract[String] val throttle: Int = (configJson \ AttributesEnum.THROTTLE.toString).extract[Int] val seed: Int = (configJson \ AttributesEnum.RANDOM_SEED.toString).extract[Int] val captchaExpiryTimeLimit: Int = (configJson \ AttributesEnum.CAPTCHA_EXPIRY_TIME_LIMIT.toString).extract[Int] @@ -60,6 +61,7 @@ class Config(configFilePath: String) { val defaultConfigMap = (AttributesEnum.RANDOM_SEED.toString -> new ju.Random().nextInt()) ~ (AttributesEnum.PORT.toString -> 8888) ~ + (AttributesEnum.ADDRESS.toString -> "0.0.0.0") ~ (AttributesEnum.CAPTCHA_EXPIRY_TIME_LIMIT.toString -> 5) ~ (AttributesEnum.THROTTLE.toString -> 1000) ~ (AttributesEnum.THREAD_DELAY.toString -> 2) ~ diff --git a/src/main/scala/lc/server/Server.scala b/src/main/scala/lc/server/Server.scala index 64f4126..5bbde20 100644 --- a/src/main/scala/lc/server/Server.scala +++ b/src/main/scala/lc/server/Server.scala @@ -9,11 +9,12 @@ import org.limium.picoserve import org.limium.picoserve.Server.ByteResponse import scala.io.Source import org.limium.picoserve.Server.StringResponse +import java.net.InetSocketAddress -class Server(port: Int, captcha: Captcha) { +class Server(address: String, port: Int, captcha: Captcha) { val server: picoserve.Server = picoserve.Server .builder() - .port(port) + .address(new InetSocketAddress(address, port)) .backlog(32) .POST( "/v1/captcha", @@ -69,7 +70,7 @@ class Server(port: Int, captcha: Captcha) { } def start(): Unit = { - println("Starting server on port:" + port) + println("Starting server on " + address + ":" + port) server.start() } }