akka-http + angular2 路由
akka-http + angular2 routing
我正在尝试从 akka-http(scala rest 框架)提供 angular2(rc3) 应用程序。由于路由,它不起作用。当请求时,spray 会尝试将 /my/endpoint/declared/in/angular
查找为普通资源。我应该怎么做?
有了简单的静态网页,没有路由(动态链接)就很容易了:
path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app")
每次找不到请求的资源时,我都尝试提供服务index.html:
path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app") ~ getFromResource("my-app/index.html")
但它破坏了相关链接(当我请求 /app/my/endpoint
时,我得到 index.html,它试图从 /app/my/endpoint/styles.css
而不是 /app/styles.css
下载 styles.css)
我想知道在其他http服务器上是怎么做到的。
我解决了这个问题。它可能不是最佳的,但效果很好。
在喷雾配置中,您输入:
path("ui") { //the same prefix must be set as base href in index.html
getFromResource("abtest-ui/index.html")
} ~ pathPrefix("ui") {
getFromResourceDirectory("abtest-ui") ~
getFromResource("abtest-ui/index.html")
}
并且在 index.html 中:
<base href="/ui/">
总结:
- 请求
/ui/
服务 index.html
- 请求
/ui/someResourceFile.css
提供此资源
- 对
/ui/AnythingThat/IsNotA/ResourceFile
的请求服务于 index.html 并且 angular 路由处理它
我正在尝试从 akka-http(scala rest 框架)提供 angular2(rc3) 应用程序。由于路由,它不起作用。当请求时,spray 会尝试将 /my/endpoint/declared/in/angular
查找为普通资源。我应该怎么做?
有了简单的静态网页,没有路由(动态链接)就很容易了:
path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app")
每次找不到请求的资源时,我都尝试提供服务index.html:
path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app") ~ getFromResource("my-app/index.html")
但它破坏了相关链接(当我请求 /app/my/endpoint
时,我得到 index.html,它试图从 /app/my/endpoint/styles.css
而不是 /app/styles.css
下载 styles.css)
我想知道在其他http服务器上是怎么做到的。
我解决了这个问题。它可能不是最佳的,但效果很好。
在喷雾配置中,您输入:
path("ui") { //the same prefix must be set as base href in index.html
getFromResource("abtest-ui/index.html")
} ~ pathPrefix("ui") {
getFromResourceDirectory("abtest-ui") ~
getFromResource("abtest-ui/index.html")
}
并且在 index.html 中:
<base href="/ui/">
总结:
- 请求
/ui/
服务 index.html - 请求
/ui/someResourceFile.css
提供此资源 - 对
/ui/AnythingThat/IsNotA/ResourceFile
的请求服务于 index.html 并且 angular 路由处理它