Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

java - How to serve static assets in Lagom?

I am trying to serve static assets with Lagom. I added a play router using additional routers because play has support for serving assets from public folder.

But I can't use Assets.at function here because it is not static. After compiling code, I also don't see the assets jar, play suppose to create.

public class FileServerRouter implements SimpleRouter {

  private final Router delegate;

  @Inject
  public FileServerRouter(RoutingDsl routingDsl) {
    this.delegate =
        routingDsl
            .GET("/assets/*file")
            .routingTo(
                (request, file) -> {
                  // Assets.at(file);
                  return ok("Serving " + file);
                })
            .build()
            .asScala();
  }

  @Override
  public PartialFunction<RequestHeader, Handler> routes() {
    return delegate.routes();
  }
}

Does anyone know how to use Assets.at with RoutingDsl or any other way to serve static assets with lagom?

question from:https://stackoverflow.com/questions/65661208/how-to-serve-static-assets-in-lagom

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...