mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-23 22:46:44 +01:00
used RawHeader class for custom headers
This commit is contained in:
parent
54f8e3170f
commit
75b1098300
1 changed files with 15 additions and 12 deletions
|
@ -5,6 +5,7 @@ import java.net.InetSocketAddress
|
|||
import akka.actor.ActorRef
|
||||
import akka.http.scaladsl.model.HttpHeader.ParsingResult
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.scaladsl.model.headers.RawHeader
|
||||
import akka.util.Timeout
|
||||
import akka.http.scaladsl.server.Directives._
|
||||
import fr.acinq.bitcoin.BinaryData
|
||||
|
@ -32,7 +33,9 @@ import org.jboss.netty.handler.codec.http.HttpHeaders
|
|||
*/
|
||||
|
||||
case class JsonRPCBody(jsonrpc: String = "1.0", id: String = "scala-client", method: String, params: Seq[JValue])
|
||||
|
||||
case class Error(code: Int, message: String)
|
||||
|
||||
case class JsonRPCRes(result: AnyRef, error: Option[Error], id: String)
|
||||
|
||||
//TODO : use Json4sSupport ?
|
||||
|
@ -43,9 +46,13 @@ trait Service extends Logging {
|
|||
implicit val formats = org.json4s.DefaultFormats + new BinaryDataSerializer + new StateSerializer + new Sha256Serializer + new ChannelDescSerializer
|
||||
implicit val timeout = Timeout(30 seconds)
|
||||
|
||||
def connect(addr: InetSocketAddress, amount: Long): Unit // amount in satoshis
|
||||
def connect(addr: InetSocketAddress, amount: Long): Unit
|
||||
|
||||
// amount in satoshis
|
||||
def register: ActorRef
|
||||
|
||||
def router: ActorRef
|
||||
|
||||
def paymentHandler: ActorRef
|
||||
|
||||
def sendCommand(channel_id: String, cmd: Command): Future[String] = {
|
||||
|
@ -55,15 +62,11 @@ trait Service extends Logging {
|
|||
})
|
||||
}
|
||||
|
||||
val customHeaders = List(
|
||||
HttpHeader.parse("Access-Control-Allow-Origin", "*"),
|
||||
HttpHeader.parse("Access-Control-Allow-Headers", "Content-Type"),
|
||||
HttpHeader.parse("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS"),
|
||||
HttpHeader.parse("Cache-control", "public, no-store, max-age=0"),
|
||||
HttpHeader.parse("Access-Control-Allow-Headers", "x-requested-with")
|
||||
).map {
|
||||
case ParsingResult.Ok(header, _) => header
|
||||
}
|
||||
val customHeaders = RawHeader("Access-Control-Allow-Origin", "*") ::
|
||||
RawHeader("Access-Control-Allow-Headers", "Content-Type") ::
|
||||
RawHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS") ::
|
||||
RawHeader("Cache-control", "public, no-store, max-age=0") ::
|
||||
RawHeader("Access-Control-Allow-Headers", "x-requested-with") :: Nil
|
||||
|
||||
val route =
|
||||
pathSingleSlash {
|
||||
|
@ -103,10 +106,10 @@ trait Service extends Logging {
|
|||
}
|
||||
|
||||
onComplete(f_res) {
|
||||
case Success(res) => complete(HttpResponse(StatusCodes.OK, headers= customHeaders, entity = HttpEntity(ContentTypes.`application/json`, Serialization.writePretty(
|
||||
case Success(res) => complete(HttpResponse(StatusCodes.OK, headers = customHeaders, entity = HttpEntity(ContentTypes.`application/json`, Serialization.writePretty(
|
||||
JsonRPCRes(res, None, json.id)
|
||||
))))
|
||||
case Failure(t) => complete(HttpResponse(StatusCodes.InternalServerError, headers= customHeaders, entity = HttpEntity(ContentTypes.`application/json`, Serialization.writePretty(
|
||||
case Failure(t) => complete(HttpResponse(StatusCodes.InternalServerError, headers = customHeaders, entity = HttpEntity(ContentTypes.`application/json`, Serialization.writePretty(
|
||||
JsonRPCRes(null, Some(Error(-1, t.getMessage)), json.id))
|
||||
)))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue