0

I want to combine Java/Scala sbt subprojects in a way that each module is a self-contained SPA micro-service. I am constrained to Spring Boot (Tomcat) to serve the files for historical reasons. I chose Scala.js to write the Javascript client side. The packaging is done with the help of sbt plugins. The relevant part of build.sbt is:

ThisBuild / scalaVersion := "2.12.6"

lazy val iamProject = ProjectRef(uri("https://github.com/iservport/iservport-iam.git"), "iam")

lazy val appCargo = (project in file("app-cargo")).enablePlugins(ScalaJSPlugin, ScalaJSWeb)

lazy val root = (project in file("."))
  .enablePlugins(JavaServerAppPackaging, UniversalDeployPlugin, AshScriptPlugin)
  .enablePlugins(DockerPlugin, SbtWeb)
  .settings(
    scalaJSProjects := Seq(appCargo),
    pipelineStages in Assets := Seq(scalaJSPipeline),
    name := "iservport-control",
    mainClass in Compile := Some("com.iservport.Application"),
...
  ).dependsOn(iamProject, appCargo)

When I expand the application zip generated by universal:packageBin, under the lib directory, I can find com.iservport.iservport-cargo-1.1.1.RELEASE.jar (the module), and:

jar -tf com.iservport.iservport-control-1.1.1.RELEASE.jar | grep cargo

…
META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/14848cb02339ea90f0c6/com/iservport/cargo/service/ShipmentService.scala
META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/iservport-cargo-opt.js.map
META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/14848cb02339ea90f0c6/com/iservport/cargo/service/ShipmentDocumentService.scala
META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/iservport-cargo-opt.js
META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/14848cb02339ea90f0c6/com/iservport/cargo/repository/ShipmentTypeRepository.scala
…

I tested Spring Boot ability to serve webjars, for example, d3.js, and I see it working. However, I can't see the same webjar mapping work for a similar resource inside my jar:

META-INF/resources/webjars/iservport-control/1.1.1.RELEASE/iservport-cargo-opt.js

I've tried with localhost:8443/webjars/iservport-control/1.1.1.RELEASE/iservport-cargo-opt.js , localhost:8443/webjars/iservport-control /iservport-cargo-opt.js and other variants, they all are 404.

How can I expose the above iservport-cargo-opt.js to the client?

1 Answers1

0

After digging into the Scala.js docs, I found out the solution:

localhost:8443/webjars/iservport-control/1.1.1.RELEASE/iservport-cargo-fastopt.js

I was testing with a local instance, created using fastOptJS, but in production ScalaJs uses fullOptJS.