Skip to content

Commit

Permalink
Config fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Karasiq committed Feb 7, 2018
1 parent edfc567 commit 8a81ce4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ object SCDesktopMain extends App {
sc.actors.regionSupervisor // Init actor

// Start server
val bindFuture = Http().bindAndHandle(httpServer.scWebAppRoutes, httpServer.httpServerSettings.host, httpServer.httpServerSettings.port)
val bindFuture = Http().bindAndHandle(httpServer.scWebAppRoutes, httpServer.httpServerConfig.host, httpServer.httpServerConfig.port)

new SCTrayIcon {
def onOpen(): Unit = {
if (Desktop.isDesktopSupported) {
Desktop.getDesktop.browse(new URI(s"http://localhost:${httpServer.httpServerSettings.port}"))
Desktop.getDesktop.browse(new URI(s"http://localhost:${httpServer.httpServerConfig.port}"))
}
}

Expand Down
5 changes: 5 additions & 0 deletions server/api-routes/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shadowcloud.http-server {
host = 127.0.0.1
port = 1911
multipart-byte-ranges = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ trait SCAkkaHttpFileRoutes { self: SCAkkaHttpApiRoutes with SCHttpServerSettings
(SCApiDirectives.extractChunkRanges(chunkStreamSize) & extractLog) { (ranges, log)
val fullRangesSize = ranges.size
ranges match {
case ranges if !httpServerSettings.useMultipartByteRanges || ranges.isOverlapping
case ranges if !httpServerConfig.multipartByteRanges || ranges.isOverlapping
log.debug("Byte ranges of size {} requested: {}", MemorySize(fullRangesSize), ranges)
val stream = sc.streams.file.readChunkStreamRanged(regionId, chunks, ranges)
respondWithHeader(`Content-Range`(toContentRange(ranges.toRange))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.karasiq.shadowcloud.server.http

import com.karasiq.common.configs.ConfigImplicits
import com.karasiq.common.configs.ConfigImplicits._
import com.karasiq.shadowcloud.ShadowCloudExtension
import com.karasiq.shadowcloud.server.http.config.SCHttpServerConfig

trait SCHttpServerSettings {
protected val sc: ShadowCloudExtension

// -----------------------------------------------------------------------
// Config
// -----------------------------------------------------------------------
object httpServerSettings extends ConfigImplicits {
val config = sc.config.rootConfig.getConfig("http-server")
val host = config.withDefault("127.0.0.1", _.getString("host"))
val port = config.withDefault(1911, _.getInt("port"))
val useMultipartByteRanges = config.getBoolean("use-multipart-byte-ranges")
}
lazy val httpServerConfig = SCHttpServerConfig(sc.config.rootConfig.getConfigIfExists("http-server"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.karasiq.shadowcloud.server.http.config

import com.typesafe.config.Config

import com.karasiq.common.configs.ConfigImplicits._
import com.karasiq.shadowcloud.config.{WrappedConfig, WrappedConfigFactory}

final case class SCHttpServerConfig(rootConfig: Config, host: String, port: Int, multipartByteRanges: Boolean) extends WrappedConfig

object SCHttpServerConfig extends WrappedConfigFactory[SCHttpServerConfig] {
def apply(config: Config): SCHttpServerConfig = {
SCHttpServerConfig(
config,
config.withDefault("127.0.0.1", _.getString("host")),
config.withDefault(1911, _.getInt("port")),
config.withDefault(true, _.getBoolean("multipart-byte-ranges"))
)
}
}
6 changes: 0 additions & 6 deletions server/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
shadowcloud.http-server {
host = 127.0.0.1
port = 1911
use-multipart-byte-ranges = true
}

akka.http.server {
idle-timeout = 60 min
request-timeout = 60 min
Expand Down

0 comments on commit 8a81ce4

Please sign in to comment.