NiosxApplicationLoader.scala 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2020 Prasoon Joshi
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. import _root_.controllers.AssetsComponents
  18. import com.softwaremill.macwire._
  19. import play.api.ApplicationLoader.Context
  20. import play.api._
  21. import play.api.i18n._
  22. import play.api.mvc._
  23. import play.api.routing.Router
  24. import router.Routes
  25. import play.filters.csrf.CSRFFilter
  26. import configuration.NiosxModule
  27. import repository._
  28. class NiosxApplicationLoader extends ApplicationLoader {
  29. def load(context: Context): Application = new NiosxComponents(context).application
  30. }
  31. class NiosxComponents(context: Context) extends BuiltInComponentsFromContext(context)
  32. with NiosxModule
  33. with I18nComponents
  34. with AssetsComponents
  35. with play.filters.cors.CORSComponents
  36. with play.filters.HttpFiltersComponents {
  37. LoggerConfigurator(context.environment.classLoader).foreach {
  38. _.configure(context.environment, context.initialConfiguration, Map.empty)
  39. }
  40. /**
  41. * If you are using compile-time dependency injection,
  42. * the runtime configuration for filters is ignored.
  43. * Instead, you need to put code into your ApplicationLoader:
  44. */
  45. override def httpFilters: Seq[EssentialFilter] = {
  46. super.httpFilters.filterNot(_.getClass == classOf[CSRFFilter]) :+ corsFilter
  47. }
  48. lazy val router: Router = {
  49. //adding prefix string in local scope for the Router constructor
  50. val prefix: String = "/"
  51. wire[Routes]
  52. }
  53. lazy val ec: NiosxExecutionContext = wire[NiosxExecutionCtxImpl]
  54. }