0

Can MSF4J application serve static content without using the Mustache template engine. I have developed a REST service which will be consumed by an already developed angular web app. Now I need to package the same angular app with the micro service so it will render in the browser and will consume the service via ajax calls.

DinushaNT
  • 1,137
  • 6
  • 17

1 Answers1

1

MSF4J does not directly support serving static content. From your question what I understood is that you want to point the MSF4J server to a directory and serve resources in that directory by their relative path or something similar. In this case what you can do is to write an MSF4J service method with a wildcard path and serve the static content that matches the path of the request.

@Path("/")
public class FileServer {

    private static final String BASE_PATH = "/your/www/dir";

    @GET
    @Path("/**")
    public Response serveFiles(@Context Request request) {
        String uri = request.getUri();
        System.out.println("Requested: " + uri);
        File file = Paths.get(BASE_PATH, uri).toFile();
        if (file.exists()) {
            return Response.ok().entity(file).build();
        } else {
            return Response.status(404).entity("<h1>Not Found</h1>").build();
        }
    }
}
Makmeksum
  • 463
  • 1
  • 4
  • 14
  • See also, from the official codebase https://github.com/wso2/msf4j/blob/master/samples/fileserver/src/main/java/org/wso2/msf4j/example/FileServer.java – Big Rich May 15 '18 at 12:02