问题
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? :)
回答1:
You can implement this in such way:
And now map routes with index.html:
来源:https://stackoverflow.com/questions/39489986/java-spark-framework-route-to-a-specific-static-file