Search code examples
javaangularjsspark-java

Java Spark Framework: Route to a specific static file


Is there a simple way of setting up routes to a specific static file using the Java Spark Framework?

I'm setting up an Angular (1.5) app to be served from a Java Spark server. I've set up the general way of serving static files:

staticFiles.location("/public");

The app will have several angular routes, e.g. /start, /config, /live, etc.

Angular will take care of the routing when the index.html and the js-files have been loaded. But I want support for loading the application directly on the /start, /config, /live pages. To accomplish this I need to serve index.html from all these routes.

With Python Flask, you can do something like this:

@app.route('/live')
@app.route('/start')
@app.route('/config')
def index():
    return app.send_static_file('index.html')

I can't find anything that looks like this in Spark.

In the long run I'll probably serve the static files from NGINX, where you can easily do this. But for now it would be really nice to be able to do this in Spark.

Anyone? :)


Solution

  • You can implement this in such way:

    enter image description here

    And now map routes with index.html:

    enter image description here