Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/lc/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/lc/core/captchaFields.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/lc/core/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) ~
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/lc/server/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
}
}