Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][Proposal] LagomPlayServiceScala plugin #1509

Closed

Conversation

guizmaii
Copy link
Contributor

@guizmaii guizmaii commented Aug 4, 2018

Pull Request Checklist

  • Have you read through the contributor guidelines?
  • Have you signed the Lightbend CLA?
  • Have you added copyright headers to new files?
  • Have you updated the documentation?
  • Have you added tests for any changed functionality?

Fixes

Fixes #xxxx

Purpose

I recently discovered the PlayService plugins.
Could be great to help people to use it in their Lagom app.

Background Context

Why did you take this approach?

References

Are there any relevant issues / PRs / mailing lists discussions?

…yService` and the `LagomPlay` plugins are enabled, not when the `PlayScala` and the `LagomPlay` are enabled.
@guizmaii guizmaii changed the title [WIP] LagomPlayScala plugin should be automatically enabled when the `Pla… [WIP][Proposal LagomPlayServiceScala plugin Aug 4, 2018
@guizmaii guizmaii changed the title [WIP][Proposal LagomPlayServiceScala plugin [WIP][Proposal] LagomPlayServiceScala plugin Aug 4, 2018
@guizmaii
Copy link
Contributor Author

guizmaii commented Aug 6, 2018

@TimMoore @ignasi35

My tests don't pass because the reloading doesn't happen.

[info] [error] java.lang.RuntimeException: 'Hello LagomPlayServiceScala app!' did not contain 'Hello changed LagomPlayServiceScala app!'

I don't understand why. Can you take a look please ?

@TimMoore
Copy link
Contributor

TimMoore commented Aug 6, 2018

@guizmaii could you add a little more context about what this pull request is for?

@guizmaii
Copy link
Contributor Author

guizmaii commented Aug 6, 2018

Hi @TimMoore

The goal of this pull request is to propose a new Lagom plugin that will permit Lagom users to develop "PlayScala" apps with the minimal PlayService Play layout.

More info on this layout: https://www.playframework.com/documentation/2.6.x/Highlights26#PlayService-sbt-plugin-(experimental)

Why is this interesting ?

We're using ReactJS to develop the web part of our app. So we don't need Twirl and co.

This app is just used to serve the JS/CSS/HTML files.
Here's our router, for example:

final class FrontEndRouter(
    env: Environment,
    assets: Assets,
    action: DefaultActionBuilder
) extends SimpleRouter {

  private lazy val npmHost = "http://localhost:3000"

  private def devRoutes: Router.Routes = {
    case GET(p"/") =>
      action {
        TemporaryRedirect(npmHost)
      }
  }

  private def prodRoutes: Router.Routes = {
    case GET(p"/frontend/health")  => action.apply(Ok("Hello World"))
    case GET(p"/static/$file*")    => assets.versioned(path = "/public/static", file = file)
    case GET(p"/*")                => assets.versioned(path = "/public", file = "index.html")
    case GET(p"/")                 => assets.versioned(path = "/public", file = "index.html")
  }

  override val routes: Router.Routes = if (env.mode == Mode.Dev) devRoutes else prodRoutes

}

Why do we need a new Lagom plugin ?

Because for now if you want to use the PlayService, you have to know a lot of Lagom internals.
Since I know a bit how Lagom works, I personally know how to use the PlayService and it's not obvious nor easy to maintain.
Here's how I do that:

import com.lightbend.lagom.sbt.{LagomImport, LagomReloadableService}
import play.sbt.PlayImport.PlayKeys
import play.sbt.PlayInternalKeys
import sbt.Keys.libraryDependencies

/**
  *
  * This is all the configurations automatically added by this `LagomPlayScala` plugin.
  * So it's equivalent to a reimplementation of the `LagomPlayScala` plugin.
  *
  * More info:
  *   - https://github.com/lagom/lagom/blob/master/dev/sbt-plugin/src/main/scala/com/lightbend/lagom/sbt/LagomPlugin.scala#L112
  *   - https://github.com/lagom/lagom/blob/master/dev/sbt-plugin/src/main/scala/com/lightbend/lagom/sbt/LagomPlugin.scala#L154
  */
object CustomLagomPlayScala {

  import LagomReloadableService.autoImport._

  val projectSettings = Seq(
    // Run the Play reload task when Lagom requests a reload
    lagomReload := PlayInternalKeys.playReload.value,
    // Play wants to add the assets classloader to the application classloader
    lagomClassLoaderDecorator := PlayInternalKeys.playAssetsClassLoader.value,
    // Watch the files that Play wants to watch
    lagomWatchDirectories := PlayKeys.playMonitoredFiles.value,
    libraryDependencies += LagomImport.lagomScaladslDevMode
  )

}
lazy val frontEnd: Project = Project(id = "frontEnd")
  .enablePlugins(LagomPlugin, PlayService, LagomReloadableService, SbtWeb)
  .settings(CustomLagomPlayScala.projectSettings: _*)

With the new plugin, all the above code would only be:

lazy val frontEnd: Project = Project(id = "frontEnd")
  .enablePlugins(LagomPlayServiceScala, SbtWeb)

@erip
Copy link
Contributor

erip commented Aug 6, 2018

I might be missing some context, but do you think it would be possible to just amend the existing PlayService plugin? Or do the required plugins change depending on the DSL?

@guizmaii
Copy link
Contributor Author

guizmaii commented Aug 11, 2018

Hi @erip,

It's not possible to just edit the current LagomPlayScala plugin because it'll not be retrocompatible.

Plus, it's a new feature that Lagom offers to its users, not a modification of a current feature.

Did I answer your questions correctly ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants