Update to the newest version of the play framework.
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
package massivedecks
|
||||
|
||||
import play.Play
|
||||
import javax.inject.Inject
|
||||
|
||||
import play.api.Configuration
|
||||
import play.api.mvc.RequestHeader
|
||||
|
||||
object Config {
|
||||
val base = Play.application().configuration()
|
||||
|
||||
def getString(key: String) = Option(base.getString(key))
|
||||
|
||||
def apply(request: RequestHeader) = new Config(request)
|
||||
/**
|
||||
* Factory for dependency injection.
|
||||
*/
|
||||
class Factory @Inject()(base: Configuration) {
|
||||
def apply(request: RequestHeader) = new Config(base, request)
|
||||
}
|
||||
}
|
||||
class Config(request: RequestHeader) {
|
||||
import Config._
|
||||
class Config(base: Configuration, request: RequestHeader) {
|
||||
def getString(key: String) = base.getString(key)
|
||||
|
||||
def protocol = getString("md_protocol").getOrElse {
|
||||
request.headers.get("X-Forwarded-Proto") match {
|
||||
|
||||
@@ -2,8 +2,10 @@ package massivedecks.controllers
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
||||
import akka.stream.scaladsl.{Flow, Sink, Source}
|
||||
import play.api.libs.json.{JsResult, JsValue, Json}
|
||||
import play.api.mvc._
|
||||
import massivedecks.exceptions._
|
||||
@@ -13,8 +15,9 @@ import massivedecks.models.Lobby.Formatters._
|
||||
import massivedecks.models.Player
|
||||
import massivedecks.models.Player.Formatters._
|
||||
import massivedecks.stores.LobbyStore
|
||||
import play.api.libs.streams.Streams
|
||||
|
||||
class API @Inject()(store: LobbyStore) extends Controller {
|
||||
class API @Inject()(store: LobbyStore) (implicit context: ExecutionContext) extends Controller {
|
||||
|
||||
def createLobby() = Action {
|
||||
wrap {
|
||||
@@ -25,11 +28,26 @@ class API @Inject()(store: LobbyStore) extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
def notifications(gameCode: String) = WebSocket.using[String] { requestHeader =>
|
||||
store.performInLobby(gameCode) { lobby =>
|
||||
lobby.register()
|
||||
def notifications(gameCode: String) = WebSocket.acceptOrResult[String, String] { requestHeader => Future {
|
||||
Try {
|
||||
store.performInLobby(gameCode) { lobby =>
|
||||
lobby.register()
|
||||
}
|
||||
} match {
|
||||
case Success((iteratee, enumerator)) =>
|
||||
val (sub, _) = Streams.iterateeToSubscriber(iteratee)
|
||||
val pub = Streams.enumeratorToPublisher(enumerator)
|
||||
Right(Flow.fromSinkAndSource(Sink.fromSubscriber(sub), Source.fromPublisher(pub)))
|
||||
|
||||
case Failure(error) =>
|
||||
error match {
|
||||
case exception: RequestException =>
|
||||
Left(Status(exception.statusCode)(exception.details.toJson()))
|
||||
case _ =>
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
} }
|
||||
|
||||
def getLobby(gameCode: String) = Action {
|
||||
wrap(store.readFromLobby(gameCode) { lobby =>
|
||||
|
||||
@@ -2,7 +2,7 @@ package massivedecks.controllers
|
||||
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
import javax.inject.Singleton
|
||||
import javax.inject.{Inject, Singleton}
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
@@ -11,14 +11,13 @@ import play.api.http.HttpErrorHandler
|
||||
import play.api.mvc.Results._
|
||||
import play.api.mvc._
|
||||
import play.api.Logger
|
||||
|
||||
import massivedecks.Config
|
||||
|
||||
@Singleton
|
||||
class ErrorHandler extends HttpErrorHandler {
|
||||
class ErrorHandler @Inject()(getConfig: Config.Factory) extends HttpErrorHandler {
|
||||
|
||||
def onClientError(request: RequestHeader, statusCode: Int, rawMessage: String) = Future.successful {
|
||||
val config = Config(request)
|
||||
val config = getConfig(request)
|
||||
val (message, description) = statusCode match {
|
||||
case 400 => ("Bad Request", "there was a problem with the request you made")
|
||||
case 403 => ("Forbidden", ",you are not able to access the resource you requested")
|
||||
@@ -31,7 +30,7 @@ class ErrorHandler extends HttpErrorHandler {
|
||||
}
|
||||
|
||||
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = Future.successful {
|
||||
val config = Config(request)
|
||||
val config = getConfig(request)
|
||||
val description = "the server had a problem trying to handle your request"
|
||||
Logger.error(exception.getMessage)
|
||||
NotFound(views.html.error(
|
||||
|
||||
@@ -9,15 +9,15 @@ import play.api.Play.current
|
||||
|
||||
import massivedecks.Config
|
||||
|
||||
class Pages @Inject() (cached: Cached) extends Controller {
|
||||
class Pages @Inject() (cached: Cached, getConfig: Config.Factory) extends Controller {
|
||||
|
||||
def index() = Cached("index")(Action { request =>
|
||||
val config = Config(request)
|
||||
def index() = cached("index")(Action { request =>
|
||||
val config = getConfig(request)
|
||||
Ok(views.html.index(config.url, config.version)).as(HTML)
|
||||
})
|
||||
|
||||
def manifest() = Cached("manifest")(Action { request =>
|
||||
val config = Config(request)
|
||||
def manifest() = cached("manifest")(Action { request =>
|
||||
val config = getConfig(request)
|
||||
val json = Json.obj(
|
||||
"name" -> "Massive Decks",
|
||||
"description" -> "An online party game inspired by Cards Against Humanity.",
|
||||
|
||||
@@ -87,6 +87,7 @@ class Game(players: Players, config: Config, notifiers: Notifiers) (implicit con
|
||||
/**
|
||||
* Begin the round.
|
||||
*
|
||||
* @param firstRound If this is the first round in the game.
|
||||
* @throws BadRequestException with key "not-enough-players" if there are not enough players in the game to begin a
|
||||
* round. The value "required" gives the minimum number of players needed for the request
|
||||
* to succeed.
|
||||
|
||||
@@ -1 +1 @@
|
||||
sbt.version=0.13.8
|
||||
sbt.version=0.13.12
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// The Play plugin
|
||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.4")
|
||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.4")
|
||||
|
||||
// web plugins
|
||||
|
||||
|
||||
Reference in New Issue
Block a user