Server

play.core.server.Server
See theServer companion trait
object Server

Utilities for creating a server that runs around a block of code.

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Server.type

Members list

Type members

Classlikes

case object ServerStoppedReason extends Reason

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait Reason
class Object
trait Matchable
class Any
Show all
Self type

Value members

Concrete methods

def withApplication[T](application: Application, config: ServerConfig)(block: Port => T)(implicit provider: ServerProvider): T

Run a block of code with a server for the given application.

Run a block of code with a server for the given application.

The passed in block takes the port that the application is running on. By default, this will be a random ephemeral port. This can be changed by passing in an explicit port with the config parameter.

Value parameters

application

The application for the server to server.

block

The block of code to run.

config

The configuration for the server. Defaults to test config with the http port bound to a random ephemeral port.

provider

The server provider.

Attributes

Returns

The result of the block of code.

def withApplicationFromContext[T](config: ServerConfig)(appProducer: Context => Application)(block: Port => T)(implicit provider: ServerProvider): T

Run a block of code with a server for the application containing routes.

Run a block of code with a server for the application containing routes.

The passed in block takes the port that the application is running on. By default, this will be a random ephemeral port. This can be changed by passing in an explicit port with the config parameter.

An easy way to set up an application with given routes is to use play.api.BuiltInComponentsFromContext with any extra components needed:

 Server.withApplicationFromContext(ServerConfig(mode = Mode.Prod, port = Some(0))) { context =>
   new BuiltInComponentsFromContext(context) with AssetsComponents with play.filters.HttpFiltersComponents {
    override def router: Router = Router.from {
      case req => assets.versioned("/testassets", req.path)
    }
  }.application
} { withClient(block)(_) }

Value parameters

appProducer

A function that takes an ApplicationLoader.Context and produces play.api.Application

block

The block of code to run.

config

The configuration for the server. Defaults to test config with the http port bound to a random ephemeral port.

provider

The server provider.

Attributes

Returns

The result of the block of code.

def withRouter[T](config: ServerConfig)(routes: PartialFunction[RequestHeader, Handler])(block: Port => T)(implicit provider: ServerProvider): T

Run a block of code with a server for the given routes.

Run a block of code with a server for the given routes.

The passed in block takes the port that the application is running on. By default, this will be a random ephemeral port. This can be changed by passing in an explicit port with the config parameter.

Value parameters

block

The block of code to run.

config

The configuration for the server. Defaults to test config with the http port bound to a random ephemeral port.

provider

The server provider.

routes

The routes for the server to server.

Attributes

Returns

The result of the block of code.

def withRouterFromComponents[T](config: ServerConfig)(routes: BuiltInComponents => PartialFunction[RequestHeader, Handler])(block: Port => T)(implicit provider: ServerProvider): T

Run a block of code with a server for the given routes, obtained from the application components

Run a block of code with a server for the given routes, obtained from the application components

The passed in block takes the port that the application is running on. By default, this will be a random ephemeral port. This can be changed by passing in an explicit port with the config parameter.

Value parameters

block

The block of code to run.

config

The configuration for the server. Defaults to test config with the http port bound to a random ephemeral port.

provider

The server provider.

routes

A function that obtains the routes from the server from the application components.

Attributes

Returns

The result of the block of code.