Java Spark Framework:路由到特定的静态文件 [英] Java Spark Framework: Route to a specific static file

查看:126
本文介绍了Java Spark Framework:路由到特定的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有使用Java Spark Framework设置到特定静态文件的路由的简单方法?

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

我正在设置要从Java Spark服务器提供服务的Angular(1.5)应用程序.我已经设置了提供静态文件的一般方法:

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");

该应用将具有多个角度路线,例如/start,/config,/live等.

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

当index.html和js文件已加载时,Angular将负责路由.但是我希望支持直接在/start,/config,/live页面上加载应用程序.为此,我需要从所有这些路由中提供index.html.

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.

使用Python Flask,您可以执行以下操作:

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')

我在Spark中找不到任何看起来像这样的东西.

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

从长远来看,我可能会提供来自NGINX的静态文件,您可以在其中轻松地执行此操作.但是就目前而言,能够在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.

有人吗?:)

推荐答案

您可以通过以下方式实现此目的:

You can implement this in such way:

现在使用index.html映射路线:

And now map routes with index.html:

这篇关于Java Spark Framework:路由到特定的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆