Created
February 1, 2018 12:41
-
-
Save yohangz/bc7d62529d91ff6afb42a8b171dd5d18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import javax.inject._ | |
import play.api.Configuration | |
import play.api.http.HttpErrorHandler | |
import play.api.mvc._ | |
/** | |
* Frontend controller managing all static resource associate routes. | |
* @param assets Assets controller reference. | |
* @param cc Controller components reference. | |
*/ | |
@Singleton | |
class FrontendController @Inject()(assets: Assets, errorHandler: HttpErrorHandler, config: Configuration, cc: ControllerComponents) extends AbstractController(cc) { | |
def index: Action[AnyContent] = assets.at("index.html") | |
def assetOrDefault(resource: String): Action[AnyContent] = if (resource.startsWith(config.get[String]("apiPrefix"))){ | |
Action.async(r => errorHandler.onClientError(r, NOT_FOUND, "Not found")) | |
} else { | |
if (resource.contains(".")) assets.at(resource) else index | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment