Skip to content

Commit

Permalink
Merge pull request #160 from tptodorov/master
Browse files Browse the repository at this point in the history
support use of templates from dependencies in development mode, by loadi...
  • Loading branch information
capotej committed Aug 16, 2014
2 parents 6052e81 + c35382d commit a29fa55
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/scala/com/twitter/finatra/FileService.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a29fa55

Please sign in to comment.