Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support use of templates from dependencies in development mode, by loadi... #160

Merged
merged 1 commit into from Aug 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/scala/com/twitter/finatra/FileService.scala
@@ -1,13 +1,14 @@
package com.twitter.finatra

import com.google.common.base.Objects
import com.twitter.finagle.{Service, SimpleFilter}
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import com.twitter.util.Future
import com.twitter.finagle.http.{Request => FinagleRequest, Response => FinagleResponse}

import org.apache.commons.io.IOUtils
import java.io.{FileInputStream, File, InputStream}
import java.io._
import javax.activation.MimetypesFileTypeMap
import com.twitter.app.App

Expand All @@ -25,12 +26,21 @@ object FileResolver {
if(config.env() == "production"){
getResourceInputStream(path)
} else {
getLocalInputStream(path)
try {
getLocalInputStream(path)
} catch {
// some of the resources might be in jar dependencies
case e: FileNotFoundException => getResourceInputStream(path)
}
}
}

private def getResourceInputStream(path: String): InputStream =
getClass.getResourceAsStream(path)
private def getResourceInputStream(path: String): InputStream = {
val ins=getClass.getResourceAsStream(path)
if (ins==null) throw new FileNotFoundException(path + " not found in resources")
ins
}


private def getLocalInputStream(path: String): InputStream = {
val file = new File(config.docRoot(), path)
Expand Down