Skip to content

Instantly share code, notes, and snippets.

@janhicken
Last active March 27, 2020 15:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janhicken/498ff7c8cfeee9621db52c295207611f to your computer and use it in GitHub Desktop.
Save janhicken/498ff7c8cfeee9621db52c295207611f to your computer and use it in GitHub Desktop.
Google Cloud Functions with Scala.js
import org.scalajs.core.tools.linker.backend.ModuleKind.CommonJSModule
enablePlugins(ScalaJSPlugin)
name := "My Cloud Function"
scalaVersion := "2.12.6"
scalaJSUseMainModuleInitializer := false
scalaJSModuleKind := CommonJSModule
libraryDependencies += "io.scalajs.npm" %%% "express" % "0.4.2"
package de.janhicken.cfwithscala
import scala.scalajs.js.annotation.JSExportTopLevel
object CloudFunctions {
@JSExportTopLevel("helloWorld")
val helloWorld: CloudFunction = (request, response) ⇒ {
response.status(200).send("Hello World!")
}
}
package de.janhicken
import io.scalajs.npm.express.{Request, Response}
import scala.scalajs.js
package object cfwithscala {
type CloudFunction = js.Function2[Request, Response, Unit]
}
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.23")
sbt fastOptJS
ln -s target/scala-2.1?/*-fastopt.js index.js
gcloud beta functions deploy helloWorld --trigger-http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment