aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2016-11-13 12:00:05 -0800
committerJakob Odersky <jakob@odersky.com>2016-11-13 12:00:05 -0800
commit4e5778cac0a8be14b072a3626567ad6342d9ce31 (patch)
treedf259f11980ef68d2339a1bb44625b2ec3630bfb
downloadplay-scalajs-chat-4e5778cac0a8be14b072a3626567ad6342d9ce31.tar.gz
play-scalajs-chat-4e5778cac0a8be14b072a3626567ad6342d9ce31.tar.bz2
play-scalajs-chat-4e5778cac0a8be14b072a3626567ad6342d9ce31.zip
Initial commit
-rw-r--r--.gitignore8
-rw-r--r--app/Filters.scala24
-rw-r--r--app/controllers/HomeController.scala24
-rw-r--r--app/views/index.scala.html5
-rw-r--r--app/views/main.scala.html25
-rw-r--r--build.sbt17
-rw-r--r--conf/application.conf1
-rw-r--r--conf/logback.xml41
-rw-r--r--conf/messages1
-rw-r--r--conf/routes10
-rw-r--r--project/build.properties1
-rw-r--r--project/plugins.sbt2
-rw-r--r--project/scaffold.sbt3
-rw-r--r--public/images/favicon.pngbin0 -> 687 bytes
-rw-r--r--public/javascripts/main.js0
-rw-r--r--public/stylesheets/main.css0
-rw-r--r--test/controllers/HomeControllerSpec.scala45
17 files changed, 207 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..eb372fc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+logs
+target
+/.idea
+/.idea_modules
+/.classpath
+/.project
+/.settings
+/RUNNING_PID
diff --git a/app/Filters.scala b/app/Filters.scala
new file mode 100644
index 0000000..81a2e15
--- /dev/null
+++ b/app/Filters.scala
@@ -0,0 +1,24 @@
+import javax.inject.Inject
+
+import play.api.http.DefaultHttpFilters
+
+import play.filters.csrf.CSRFFilter
+import play.filters.headers.SecurityHeadersFilter
+import play.filters.hosts.AllowedHostsFilter
+
+/**
+ * Add the following filters by default to all projects
+ *
+ * https://www.playframework.com/documentation/latest/ScalaCsrf
+ * https://www.playframework.com/documentation/latest/AllowedHostsFilter
+ * https://www.playframework.com/documentation/latest/SecurityHeaders
+ */
+class Filters @Inject() (
+ csrfFilter: CSRFFilter,
+ allowedHostsFilter: AllowedHostsFilter,
+ securityHeadersFilter: SecurityHeadersFilter
+) extends DefaultHttpFilters(
+ csrfFilter,
+ allowedHostsFilter,
+ securityHeadersFilter
+) \ No newline at end of file
diff --git a/app/controllers/HomeController.scala b/app/controllers/HomeController.scala
new file mode 100644
index 0000000..2032080
--- /dev/null
+++ b/app/controllers/HomeController.scala
@@ -0,0 +1,24 @@
+package controllers
+
+import javax.inject._
+import play.api._
+import play.api.mvc._
+
+/**
+ * This controller creates an `Action` to handle HTTP requests to the
+ * application's home page.
+ */
+@Singleton
+class HomeController @Inject() extends Controller {
+
+ /**
+ * Create an Action to render an HTML page.
+ *
+ * The configuration in the `routes` file means that this method
+ * will be called when the application receives a `GET` request with
+ * a path of `/`.
+ */
+ def index = Action { implicit request =>
+ Ok(views.html.index())
+ }
+}
diff --git a/app/views/index.scala.html b/app/views/index.scala.html
new file mode 100644
index 0000000..68d37fb
--- /dev/null
+++ b/app/views/index.scala.html
@@ -0,0 +1,5 @@
+@()
+
+@main("Welcome to Play") {
+ <h1>Welcome to Play!</h1>
+}
diff --git a/app/views/main.scala.html b/app/views/main.scala.html
new file mode 100644
index 0000000..808a8b8
--- /dev/null
+++ b/app/views/main.scala.html
@@ -0,0 +1,25 @@
+@*
+ * This template is called from the `index` template. This template
+ * handles the rendering of the page header and body tags. It takes
+ * two arguments, a `String` for the title of the page and an `Html`
+ * object to insert into the body of the page.
+ *@
+@(title: String)(content: Html)
+
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ @* Here's where we render the page title `String`. *@
+ <title>@title</title>
+ <link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
+ <link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
+
+ </head>
+ <body>
+ @* And here's where we render the `Html` object containing
+ * the page content. *@
+ @content
+
+ <script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
+ </body>
+</html>
diff --git a/build.sbt b/build.sbt
new file mode 100644
index 0000000..3a529fe
--- /dev/null
+++ b/build.sbt
@@ -0,0 +1,17 @@
+name := """play-scalajs-chat"""
+organization := "com.lihaoyi"
+
+version := "1.0-SNAPSHOT"
+
+lazy val root = (project in file(".")).enablePlugins(PlayScala)
+
+scalaVersion := "2.11.8"
+
+libraryDependencies += filters
+libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
+
+// Adds additional packages into Twirl
+//TwirlKeys.templateImports += "com.lihaoyi.controllers._"
+
+// Adds additional packages into conf/routes
+// play.sbt.routes.RoutesKeys.routesImport += "com.lihaoyi.binders._"
diff --git a/conf/application.conf b/conf/application.conf
new file mode 100644
index 0000000..cb94680
--- /dev/null
+++ b/conf/application.conf
@@ -0,0 +1 @@
+# https://www.playframework.com/documentation/latest/Configuration
diff --git a/conf/logback.xml b/conf/logback.xml
new file mode 100644
index 0000000..9df7f6e
--- /dev/null
+++ b/conf/logback.xml
@@ -0,0 +1,41 @@
+<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
+<configuration>
+
+ <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${application.home:-.}/logs/application.log</file>
+ <encoder>
+ <pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="FILE" />
+ </appender>
+
+ <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="STDOUT" />
+ </appender>
+
+ <logger name="play" level="INFO" />
+ <logger name="application" level="DEBUG" />
+
+ <!-- Off these ones as they are annoying, and anyway we manage configuration ourselves -->
+ <logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
+ <logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
+ <logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
+ <logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
+
+ <root level="WARN">
+ <!--<appender-ref ref="ASYNCFILE" />-->
+ <appender-ref ref="ASYNCSTDOUT" />
+ </root>
+
+</configuration>
diff --git a/conf/messages b/conf/messages
new file mode 100644
index 0000000..0226738
--- /dev/null
+++ b/conf/messages
@@ -0,0 +1 @@
+# https://www.playframework.com/documentation/latest/ScalaI18N
diff --git a/conf/routes b/conf/routes
new file mode 100644
index 0000000..2ac6b33
--- /dev/null
+++ b/conf/routes
@@ -0,0 +1,10 @@
+# Routes
+# This file defines all application routes (Higher priority routes first)
+# https://www.playframework.com/documentation/latest/ScalaRouting
+# ~~~~
+
+# An example controller showing a sample home page
+GET / controllers.HomeController.index
+
+# Map static resources from the /public folder to the /assets URL path
+GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
diff --git a/project/build.properties b/project/build.properties
new file mode 100644
index 0000000..27e88aa
--- /dev/null
+++ b/project/build.properties
@@ -0,0 +1 @@
+sbt.version=0.13.13
diff --git a/project/plugins.sbt b/project/plugins.sbt
new file mode 100644
index 0000000..b772558
--- /dev/null
+++ b/project/plugins.sbt
@@ -0,0 +1,2 @@
+// The Play plugin
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.9")
diff --git a/project/scaffold.sbt b/project/scaffold.sbt
new file mode 100644
index 0000000..91355f7
--- /dev/null
+++ b/project/scaffold.sbt
@@ -0,0 +1,3 @@
+// Defines scaffolding (found under .g8 folder)
+// sbt "g8Scaffold form"
+addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.7.1")
diff --git a/public/images/favicon.png b/public/images/favicon.png
new file mode 100644
index 0000000..c7d92d2
--- /dev/null
+++ b/public/images/favicon.png
Binary files differ
diff --git a/public/javascripts/main.js b/public/javascripts/main.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/public/javascripts/main.js
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/public/stylesheets/main.css
diff --git a/test/controllers/HomeControllerSpec.scala b/test/controllers/HomeControllerSpec.scala
new file mode 100644
index 0000000..836e3ef
--- /dev/null
+++ b/test/controllers/HomeControllerSpec.scala
@@ -0,0 +1,45 @@
+package controllers
+
+import org.scalatestplus.play._
+import play.api.test._
+import play.api.test.Helpers._
+
+/**
+ * Add your spec here.
+ * You can mock out a whole application including requests, plugins etc.
+ *
+ * For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
+ */
+class HomeControllerSpec extends PlaySpec with OneAppPerTest {
+
+ "HomeController GET" should {
+
+ "render the index page from a new instance of controller" in {
+ val controller = new HomeController
+ val home = controller.index().apply(FakeRequest())
+
+ status(home) mustBe OK
+ contentType(home) mustBe Some("text/html")
+ contentAsString(home) must include ("Welcome to Play")
+ }
+
+ "render the index page from the application" in {
+ val controller = app.injector.instanceOf[HomeController]
+ val home = controller.index().apply(FakeRequest())
+
+ status(home) mustBe OK
+ contentType(home) mustBe Some("text/html")
+ contentAsString(home) must include ("Welcome to Play")
+ }
+
+ "render the index page from the router" in {
+ // Need to specify Host header to get through AllowedHostsFilter
+ val request = FakeRequest(GET, "/").withHeaders("Host" -> "localhost")
+ val home = route(app, request).get
+
+ status(home) mustBe OK
+ contentType(home) mustBe Some("text/html")
+ contentAsString(home) must include ("Welcome to Play")
+ }
+ }
+}