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


Scala Server类代码示例

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


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

示例1: 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

示例2: Blaze

//设置package包名称以及导入依赖的类
package org.mdoc.rendering.service

import eu.timepit.properly.Property
import eu.timepit.properly.Property.PropertySyntax
import org.http4s.server.Server
import org.http4s.server.blaze.BlazeBuilder
import scalaz.concurrent.Task

object Blaze {
  val httpHost: Property[String] = {
    val defaultHost = "::"
    Property.getOrElse("HTTP_HOST", defaultHost)
  }

  val httpPort: Property[Int] = {
    val defaultPort = 8081
    Property.getAsIntOrElse("HTTP_PORT", defaultPort)
  }

  val serverBuilder: Property[BlazeBuilder] =
    for {
      host <- httpHost
      port <- httpPort
    } yield {
      BlazeBuilder
        .bindHttp(port, host)
        .mountService(Service.route)
    }

  val server: Task[Server] =
    serverBuilder.runTask.flatMap(_.start)
} 
开发者ID:m-doc,项目名称:rendering-service,代码行数:33,代码来源:Blaze.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: 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

示例6: Yolo

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

import eveapi.oauth._
import OAuth2._
import scalaz._, Scalaz._
import scalaz.concurrent.Task
import eveapi.errors._
import org.http4s._, org.http4s.dsl._
import org.http4s.server.Server
import org.http4s.server.blaze._
import org.atnos.eff._, org.atnos.eff.syntax.all._, org.atnos.eff.all._
import java.time.Clock
import java.util.concurrent.CountDownLatch

case class Yolo(oauth: OAuth2, token: OAuth2Token) {
  def run[T](api: Api[T]): T = Yolo.deeff(api).run((oauth, token)).unsafePerformSync.leftMap(err => throw err).merge
  def run[T](free: Free[Lift.Link, T]): T = Yolo.deeff(free.foldMap(Execute.OAuthInterpreter)).run((oauth, token)).unsafePerformSync.leftMap(err => throw err).merge
}

object Yolo {
  def deeff[T](api: Api[T]): Reader[(OAuth2, OAuth2Token), Task[\/[EveApiError, T]]] =
    Reader({case (oauth, token) =>
      Eff.detach[Task, \/[EveApiError, T]](api.runReader[OAuth2](oauth).runState(token).map(_._1).runDisjunction)
    })

  val client = org.http4s.client.blaze.PooledHttp1Client()
  val seed = new java.security.SecureRandom().nextLong
  val clock = Clock.systemUTC()

  def oauth2(callback: Uri, clientId: String, clientSecret: String, scope: String): OAuth2 = OAuth2(client,
    OAuth2Settings(
      Uri.uri("https://login.eveonline.com/oauth/authorize"),
      Uri.uri("https://login.eveonline.com/oauth/token"),
      callback,
      Uri.uri("https://login.eveonline.com/oauth/verify"),
      clientId,
      clientSecret,
      Uri.uri("https://login.eveonline.com/oauth/token"),
      Some(scope)
    ), OAuth2State(seed), clock, OAuth2ClientSettings("login"))

  // Thanks to @rossabaker
  def genToken(oauth: OAuth2): Task[Yolo] =
    Task.async[Yolo]({ k =>
      val latch = new CountDownLatch(1)
      val service = oauth.oauthService({
        token => k(\/-(Yolo(oauth, token))); Ok("Done.").map({x =>latch.countDown(); x})
      })
      val port = oauth.settings.callbackUri.port.getOrElse(80)
      val server: Server = BlazeBuilder.mountService(Kleisli(service).local({x => println(x); x})).bindHttp(port, "localhost").run
      println(s"Go to http://localhost:${port}/login")
      latch.await()
      server.shutdown.unsafePerformSync
    })
} 
开发者ID:scala-eveapi,项目名称:eveapi,代码行数:56,代码来源:yolo.scala

示例7: 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

示例8: 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

示例9: 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

示例10: 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

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