navige
navige

Reputation: 2517

Finatra downloads HTML file instead of displaying it

I am using Finatra 2.1.6 with this code:

get("/:*") { request: Request =>
response.ok.fileOrIndex(
  request.params("*"),
  "index.html")
}

If I run this from e.g. IntelliJ, it works perfectly fine and displays the html file. However, if I start the server from an assembled jar (using sbt assembly), it does not: Whenever I try to access index.html, which I put in src/resources/index.html, it tries to download the file since the contentType is set to application/octet-stream instead of e.g., text/html.

How can I change the behaviour so it renders the html file (or css, js,...) rather than downloading it?

Upvotes: 2

Views: 178

Answers (1)

navige
navige

Reputation: 2517

Finally could solve the problem. My merge strategy for sbt assembly would be something like

val meta = """META.INF(.)*""".r
assemblyMergeStrategy in assembly := {
  ...
  case meta(_) => MergeStrategy.discard
  ...
}

which would discard the file mime.types which denotes what MIME type to use for a given file extension. I changed this to

val metaMime = """META.INF(.)mime.types""".r
val meta = """META.INF(.)*""".r
assemblyMergeStrategy in assembly := {
  ...
  case metaMime(_) => MergeStrategy.deduplicate
  case meta(_) => MergeStrategy.discard
  ...
}

and now it works perfectly fine.

Upvotes: 3

Related Questions