aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2016-11-13 14:02:14 -0800
committerJakob Odersky <jakob@odersky.com>2016-11-13 14:02:14 -0800
commite317debf1a5d639c9a5fde0f0353a7b3b7ae86a0 (patch)
treefd0821029975be254ebe47565fae0e991d443151 /server
parent4e5778cac0a8be14b072a3626567ad6342d9ce31 (diff)
downloadplay-scalajs-chat-e317debf1a5d639c9a5fde0f0353a7b3b7ae86a0.tar.gz
play-scalajs-chat-e317debf1a5d639c9a5fde0f0353a7b3b7ae86a0.tar.bz2
play-scalajs-chat-e317debf1a5d639c9a5fde0f0353a7b3b7ae86a0.zip
Basic composite app with uPickle
Diffstat (limited to 'server')
-rw-r--r--server/app/controllers/HomeController.scala28
-rw-r--r--server/app/views/index.scala.html9
-rw-r--r--server/app/views/main.scala.html24
-rw-r--r--server/conf/application.conf1
-rw-r--r--server/conf/logback.xml41
-rw-r--r--server/conf/messages1
-rw-r--r--server/conf/routes11
-rw-r--r--server/public/images/favicon.pngbin0 -> 687 bytes
-rw-r--r--server/public/javascripts/main.js0
-rw-r--r--server/public/stylesheets/main.css0
-rw-r--r--server/test/controllers/HomeControllerSpec.scala45
11 files changed, 160 insertions, 0 deletions
diff --git a/server/app/controllers/HomeController.scala b/server/app/controllers/HomeController.scala
new file mode 100644
index 0000000..13bc8dc
--- /dev/null
+++ b/server/app/controllers/HomeController.scala
@@ -0,0 +1,28 @@
+package controllers
+
+import play.api._
+import play.api.mvc._
+import upickle.default._
+
+/**
+ * This controller creates an `Action` to handle HTTP requests to the
+ * application's home page.
+ */
+class HomeController 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())
+ }
+
+ def message = Action { implicit request =>
+ Ok(write(chat.Message("hello")))
+ }
+
+}
diff --git a/server/app/views/index.scala.html b/server/app/views/index.scala.html
new file mode 100644
index 0000000..911bdaf
--- /dev/null
+++ b/server/app/views/index.scala.html
@@ -0,0 +1,9 @@
+@()
+
+@main("Welcome to Play") {
+ <main id="root">placeholder</main>
+ <script src="@routes.Assets.versioned("client-fastopt.js")" type="text/javascript"></script>
+ <script type="text/javascript">
+ chat.Main().main()
+ </script>
+}
diff --git a/server/app/views/main.scala.html b/server/app/views/main.scala.html
new file mode 100644
index 0000000..0e9906e
--- /dev/null
+++ b/server/app/views/main.scala.html
@@ -0,0 +1,24 @@
+@*
+ * 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/server/conf/application.conf b/server/conf/application.conf
new file mode 100644
index 0000000..cb94680
--- /dev/null
+++ b/server/conf/application.conf
@@ -0,0 +1 @@
+# https://www.playframework.com/documentation/latest/Configuration
diff --git a/server/conf/logback.xml b/server/conf/logback.xml
new file mode 100644
index 0000000..9df7f6e
--- /dev/null
+++ b/server/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/server/conf/messages b/server/conf/messages
new file mode 100644
index 0000000..0226738
--- /dev/null
+++ b/server/conf/messages
@@ -0,0 +1 @@
+# https://www.playframework.com/documentation/latest/ScalaI18N
diff --git a/server/conf/routes b/server/conf/routes
new file mode 100644
index 0000000..ca64d25
--- /dev/null
+++ b/server/conf/routes
@@ -0,0 +1,11 @@
+# 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
+GET /message controllers.HomeController.message
+
+# 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/server/public/images/favicon.png b/server/public/images/favicon.png
new file mode 100644
index 0000000..c7d92d2
--- /dev/null
+++ b/server/public/images/favicon.png
Binary files differ
diff --git a/server/public/javascripts/main.js b/server/public/javascripts/main.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/server/public/javascripts/main.js
diff --git a/server/public/stylesheets/main.css b/server/public/stylesheets/main.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/server/public/stylesheets/main.css
diff --git a/server/test/controllers/HomeControllerSpec.scala b/server/test/controllers/HomeControllerSpec.scala
new file mode 100644
index 0000000..836e3ef
--- /dev/null
+++ b/server/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")
+ }
+ }
+}