Merge pull request #94 from vinceh121/master

Listen address in config
This commit is contained in:
hrj 2021-05-19 20:16:01 +05:30 committed by GitHub
commit ab9c0e6247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 4 deletions

View File

@ -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()
}
}

View File

@ -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")

View File

@ -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) ~

View File

@ -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()
}
}