当前位置: 首页>>代码示例>>Scala>>正文


Scala ServerApp类代码示例

本文整理汇总了Scala中org.http4s.server.ServerApp的典型用法代码示例。如果您正苦于以下问题:Scala ServerApp类的具体用法?Scala ServerApp怎么用?Scala ServerApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServerApp类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: Server

//设置package包名称以及导入依赖的类
package foobar

import foobar.page.{Contact, Index}
import org.http4s.MediaType.`text/html`
import org.http4s.dsl._
import org.http4s.headers.`Content-Type`
import org.http4s.server.ServerApp
import org.http4s.server.blaze._
import org.http4s.{HttpService, Response, StaticFile}

import scala.io.Source
import scala.util.Try
import scalatags.Text.TypedTag
import scalaz.concurrent.Task

object Server extends ServerApp {

  def page(p: TypedTag[String]): Task[Response] =
    Ok(p.render).withContentType(Some(`Content-Type`(`text/html`)))

  val service = HttpService {
    case GET -> Root              => page(Index.page)
    case GET -> Root / "contact"  => page(Contact.page)
    case req @ GET -> Root / path =>
      println("file: " + Try(Source.fromFile(path).getLines().mkString))
      StaticFile.fromResource(path.toString, Some(req)).fold(NotFound())(Task.now)
  }

  def server(args: List[String]) =
    BlazeBuilder.bindHttp(8080)
      .mountService(service, "/")
      .start
} 
开发者ID:julien-truffaut,项目名称:FooBar,代码行数:34,代码来源:Server.scala

示例2: Boot

//设置package包名称以及导入依赖的类
package me.davidvuong.http_api

import doobie.hikari.hikaritransactor
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.syntax._
import org.http4s.HttpService
import org.log4s._
import doobie.hikari.imports._

import scalaz.concurrent._
import me.davidvuong.http_api.config.Config
import me.davidvuong.http_api.http.services.MessageHttpService
import me.davidvuong.http_api.repository.Repository
import me.davidvuong.http_api.services.MessageService
import me.davidvuong.http_api.utils.SqsQueueService

object Boot extends ServerApp {
  
  val httpService: HttpService = List(
    MessageHttpService(messageService).service
  ).reduce(_ orElse _)

  def server(args: List[String]): Task[Server] = {
    BlazeBuilder
      .bindHttp(config.http.port, config.http.host)
      .mountService(httpService)
      .withConnectorPoolSize(config.http.threadCount)
      .start
  }
} 
开发者ID:davidvuong,项目名称:docker-compose-bp,代码行数:32,代码来源:Boot.scala

示例3: Main

//设置package包名称以及导入依赖的类
package io.grhodes.mcm.server

import java.nio.file.Paths

import com.typesafe.config.ConfigFactory
import io.grhodes.mcm.server.apn.ApnService
import io.grhodes.mcm.server.gcm.XmppBuilder
import org.http4s.server.SSLSupport.StoreInfo
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.{Server, ServerApp}

import scalaz.concurrent.Task

object Main extends ServerApp {

  //System.setProperty("javax.net.debug", "all")
  System.setProperty("file.encoding", "UTF8")

  val ServerConfig = ConfigFactory.load().getConfig("io.grhodes.mcm-server")
  val KeyStoreConfig = ServerConfig.getConfig("apn.keystore")
  val KeyPath = Paths.get(KeyStoreConfig.getString("path")).toAbsolutePath.toString

  val ApnServer = BlazeBuilder.enableHttp2(true).withSSL(
      StoreInfo(KeyPath, KeyStoreConfig.getString("password")),
      keyManagerPassword = KeyStoreConfig.getString("manager-password"),
      trustStore = Some(StoreInfo(KeyPath, KeyStoreConfig.getString("password")))
    ).mountService(McmService.service, "/").bindHttp(ServerConfig.getInt("apn.port"))

  override def server(args: List[String]): Task[Server] = {
    XmppBuilder.start()
    ApnServer.start
  }

  override def shutdown(server: Server) = {
    XmppBuilder.shutdown()
    server.shutdown
  }

} 
开发者ID:grahamar,项目名称:mcm-server,代码行数:40,代码来源:Main.scala

示例4: Bootstrap

//设置package包名称以及导入依赖的类
import api.StatusApi
import com.typesafe.scalalogging.LazyLogging
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze.BlazeBuilder
import utils._
import Global._
import repository.Ds._
import scalaz._, Scalaz._
import scalaz.concurrent.Task

object Bootstrap extends ServerApp with LazyLogging {

  case class ProgramStatus(s: Server, u: Unit)

  def server(args: List[String]): Task[Server] = {

    import CustomExecutor._
    import ApplicativeTask._

    val serverTask = BlazeBuilder.bindHttp(
      port = cfgVevo.getInt("http.port"),
      host = "0.0.0.0")
      .mountService(StatusApi.service, "/status").start

    T.apply2(
      Task.fork(serverTask)(ec),
      Task.fork(Task.delay(println("hellow world from Applicatives!")))(customExecutor))(ProgramStatus(_, _)
    ) map (_.s)
  }
} 
开发者ID:kayvank,项目名称:q2io-skeleton.g8,代码行数:31,代码来源:Bootstrap.scala

示例5: Main

//设置package包名称以及导入依赖的类
package kafka.console
package service

import journal.Logger
import org.http4s.server.ServerApp

object Main extends ServerApp {

  import logging._

  implicit val log = Logger[this.type]

  override def server(args: List[String]) = for {
    _  <- info("Starting web-console...")
    cf <- config.load
    _  <- describe(cf)
    sc <- config.service(cf)
    ac <- config.app(cf)
    ct <- Context.container(ac)
    s  <- Server.start(sc, Application.instance, ct)
  } yield s

} 
开发者ID:kafka-web-console,项目名称:service,代码行数:24,代码来源:Main.scala

示例6: Demo

//设置package包名称以及导入依赖的类
package com.gvolpe.http4s.auth.demo

import com.gvolpe.http4s.auth.demo.endpoint.DemoHttpEndpoint
import com.gvolpe.http4s.auth.model.{HttpToken, HttpUser}
import com.gvolpe.http4s.auth.repository.TokenRepository
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.{Server, ServerApp}

import scalaz.concurrent.Task
import scalaz.{\/, \/-}

object Demo extends ServerApp {

  implicit val tokenRepository = new TokenRepository {
    val fakeUser = HttpUser("gvolpe", HttpUser.createToken("gvolpe"))
    println(fakeUser.httpToken) // Just to see the generated token to use in the headers
    override def find(token: HttpToken): Task[Option[HttpUser]] = Task.now(Some(fakeUser))
    override def remove(user: HttpUser): Task[\/[Throwable, Unit]] = Task.now(\/-())
    override def save(user: HttpUser): Task[\/[Throwable, Unit]] = Task.now(\/-())
  }

  override def server(args: List[String]): Task[Server] =
    BlazeBuilder
      .bindHttp(8080, "localhost")
      //.mountService(AuthHttpEndpoint.service) IT WON'T WORK BECAUSE IT'S BASED ON Http4s v0.14.6!!!
      .mountService(DemoHttpEndpoint.service)
      .start

} 
开发者ID:gvolpe,项目名称:http4s-auth-015-demo,代码行数:30,代码来源:Demo.scala

示例7: Bootstrap

//设置package包名称以及导入依赖的类
package com.markglh.blog

import java.io.File

import com.typesafe.config.ConfigFactory
import org.http4s.server.ServerApp
import org.http4s.server.blaze.BlazeBuilder

import scala.concurrent.ExecutionContext

object Bootstrap extends ServerApp {
  implicit val executionContext = ExecutionContext.global

  // This looks to (an optional) boot-configuration.conf first, then falls back to application.conf for any values not found
  // The idea is we can easily define an env specific config at runtime using volume mounts at $APP_CONF
  lazy val config = ConfigFactory
    .parseFile(new File(s"${sys.env.getOrElse("APP_CONF", ".")}/boot-configuration.conf"))
    .withFallback(ConfigFactory.load())

  override def server(args: List[String]) = BlazeBuilder.bindHttp(80, "0.0.0.0")
    .mountService(AggregatorService.routes(config.getString("tracking.service.host"),
      config.getString("beacon.service.host")), "/")
    .start
} 
开发者ID:markglh,项目名称:composing-microservices-with-sbt-docker,代码行数:25,代码来源:Bootstrap.scala

示例8: Bootstrap

//设置package包名称以及导入依赖的类
package com.markglh.blog

import java.io.File

import com.typesafe.config.ConfigFactory
import io.getquill.{CassandraAsyncContext, SnakeCase}
import org.http4s.server.ServerApp
import org.http4s.server.blaze.BlazeBuilder

import scala.concurrent.ExecutionContext

object Bootstrap extends ServerApp with Cassandra {
  implicit val executionContext = ExecutionContext.global

  // This looks to (an optional) boot-configuration.conf first, then falls back to application.conf for any values not found
  // The idea is we can easily define an env specific config at runtime using volume mounts at $APP_CONF
  lazy val config = ConfigFactory
    .parseFile(new File(s"${sys.env.getOrElse("APP_CONF", ".")}/boot-configuration.conf"))
    .withFallback(ConfigFactory.load())

  override def server(args: List[String]) = BlazeBuilder.bindHttp(80, "0.0.0.0")
    .mountService(TrackingService.routes(new TrackingRepo[CassandraAsyncContext[SnakeCase]]()), "/")
    .start
} 
开发者ID:markglh,项目名称:composing-microservices-with-sbt-docker,代码行数:25,代码来源:Bootstrap.scala

示例9: Bootstrap

//设置package包名称以及导入依赖的类
package com.markglh.blog

import java.io.File

import com.typesafe.config.ConfigFactory
import io.getquill.{CassandraAsyncContext, SnakeCase}
import org.http4s.server.ServerApp
import org.http4s.server.blaze.BlazeBuilder

import scala.concurrent.ExecutionContext

object Bootstrap extends ServerApp with Cassandra {
  implicit val executionContext = ExecutionContext.global

  // This looks to (an optional) boot-configuration.conf first, then falls back to application.conf for any values not found
  // The idea is we can easily define an env specific config at runtime using volume mounts at $APP_CONF
  lazy val config = ConfigFactory
    .parseFile(new File(s"${sys.env.getOrElse("APP_CONF", ".")}/boot-configuration.conf"))
    .withFallback(ConfigFactory.load())

  override def server(args: List[String]) = BlazeBuilder.bindHttp(80, "0.0.0.0")
    .mountService(BeaconService.routes(new BeaconRepo[CassandraAsyncContext[SnakeCase]]()), "/")
    .start
} 
开发者ID:markglh,项目名称:composing-microservices-with-sbt-docker,代码行数:25,代码来源:Bootstrap.scala

示例10: Demo2

//设置package包名称以及导入依赖的类
package com.gvolpe.http4s.auth.demo

import com.gvolpe.http4s.auth.demo.endpoint.DemoHttpEndpoint
import com.gvolpe.http4s.auth.model.{HttpToken, HttpUser}
import com.gvolpe.http4s.auth.repository.TokenRepository
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.{Server, ServerApp}

import scalaz.{\/, \/-}
import scalaz.concurrent.Task


object Demo2 extends ServerApp {

  implicit val tokenRepository = new TokenRepository {
    val fakeUser = HttpUser("gvolpe", HttpUser.createToken("gvolpe"))
    println(fakeUser.httpToken) // Just to see the generated token to use in the headers
    override def find(token: HttpToken): Task[Option[HttpUser]] = Task.now(Some(fakeUser))
    override def remove(user: HttpUser): Task[\/[Throwable, Unit]] = Task.now(\/-())
    override def save(user: HttpUser): Task[\/[Throwable, Unit]] = Task.now(\/-())
  }

  override def server(args: List[String]): Task[Server] = {
    BlazeBuilder
      .bindHttp(8080, "localhost")
      .mountService(DemoHttpEndpoint.service)
      .start
  }

} 
开发者ID:gvolpe,项目名称:http4s-auth,代码行数:31,代码来源:Demo2.scala

示例11: ServerMain

//设置package包名称以及导入依赖的类
package science.wasabi.tini.web


import java.io.File

import org.http4s._
import org.http4s.dsl._
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze.BlazeBuilder
import science.wasabi.tini.Helper

import scalaz.concurrent.Task


object ServerMain extends ServerApp {

  val helloWorldService = HttpService {
    case GET -> Root / "hello" / name =>
      Ok(s"${Helper.greeting}, $name.")
  }

  val service = HttpService {
    case request @ GET -> Root / "index.html" =>
      StaticFile.fromFile(new File("./index.html"), Some(request))
        .map(Task.now) // This one is require to make the types match up
        .getOrElse(NotFound()) // In case the file doesn't exist
  }

  override def server(args: List[String]): Task[Server] = {
    println("TiniBot2.0:  http://localhost:8080/index.html")

    BlazeBuilder
      .bindHttp(8080, "localhost")
      .mountService(helloWorldService, "/api")
      .mountService(service)
      .start
  }

  Task {
    println("Press ENTER to stop Server ...")
    System.in.read()
    System.exit(0)
  }.unsafePerformAsync( f => {
    System.err.println(f)
  })

} 
开发者ID:Giymo11,项目名称:TiniBot2.0,代码行数:48,代码来源:ServerMain.scala

示例12: Main

//设置package包名称以及导入依赖的类
package tesslasimulator.webService

import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.middleware.{CORS, GZip}
import org.http4s.server.{Server, ServerApp}

import scalaz.concurrent.Task

object Main extends ServerApp {
  case class Config(port: Int = 8080, hostname: String = "localhost")

  override def server(args: List[String]): Task[Server] = {
    val cliParser = new scopt.OptionParser[Config]("TeSSLa Simulator Server") {
      opt[Int]('p', "port")
        .optional()
        .valueName("<port>")
        .action((x, c) => c.copy(port = x))
        .text("port to bind to - defaults to 8080")

      opt[String]('h', "hostname")
        .optional()
        .valueName("<hostname>")
        .action((x, c) => c.copy(hostname = x))
        .text("hostname to bind to - defaults to localhost")

      help("help").text("prints this usage text")
    }

    val config = cliParser.parse(args, Config()).get

    BlazeBuilder
      .bindHttp(config.port, config.hostname)
      .mountService(GZip(CORS(SimulatorService.service)))
      .start
  }
} 
开发者ID:Be-ngt-oH,项目名称:TeSSLaSim,代码行数:37,代码来源:Main.scala

示例13: JamServer

//设置package包名称以及导入依赖的类
package ch.mirichan.jam.server

import java.util.concurrent.{ExecutorService, Executors}

import ch.mirichan.jam.server.storage.config.LocalFileConfigResource
import ch.mirichan.jam.server.storage.filesystem.LocalFilesystem

import scala.util.Properties.envOrNone
import scalaz.concurrent.Task
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze.BlazeBuilder


object JamServer extends ServerApp {

  val port : Int              = envOrNone("HTTP_PORT") map (_.toInt) getOrElse 8080
  val host : String           = "0.0.0.0"
  val pool : ExecutorService  = Executors.newCachedThreadPool()

  override def server(args: List[String]): Task[Server] = {
    val config = LocalFileConfigResource(LocalFilesystem).read
    BlazeBuilder
      .bindHttp(port, host)
      .mountService(RestApi.service)
      .withServiceExecutor(pool)
      .start
  }
} 
开发者ID:mirichan,项目名称:jam,代码行数:29,代码来源:JamServer.scala

示例14: Main

//设置package包名称以及导入依赖的类
import controllers.HelloController
import org.http4s.HttpService
import org.http4s.dsl._
import org.http4s.server.blaze.BlazeBuilder
import org.http4s.server.{Server, ServerApp}
import org.log4s.getLogger

import scalaz.concurrent.Task

object Main extends ServerApp {
  private val logger = getLogger

  val routes = HttpService {
    case r @ GET -> Root / "hello" / name => HelloController.index(name)(r)
  }

  val service: HttpService = routes.local { req =>
    logger.info(s"${req.remoteAddr
      .getOrElse("null")} -> ${req.method}: ${req.uri.path} ${req.uri.query}")
    req
  }

  override def server(args: List[String]): Task[Server] = {
    for {
      config <- Config.fromEnv()
      server <- BlazeBuilder
        .bindHttp(config.port, "localhost")
        .mountService(service)
        .start
    } yield server
  }
} 
开发者ID:nicolashery,项目名称:example-marvel-scala,代码行数:33,代码来源:Main.scala


注:本文中的org.http4s.server.ServerApp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。