-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4e7d1f
commit 8dc70e9
Showing
45 changed files
with
12,079 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
logs | ||
target | ||
/.idea | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/.settings | ||
/RUNNING_PID | ||
/public |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2017 Yohan Gomez | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,187 @@ | ||
# TravelBerlin | ||
CS2340 Project | ||
[![MIT License][license-badge]][LICENSE] | ||
|
||
# Scala Play React Seed | ||
|
||
> Use play framework to develop the web application backend/services and frontend using React Create App, all in a totally integrated workflow and single unified console. This approach will deliver perfect development experience without CORS hassle. | ||
|
||
Read more @ http://bit.ly/2A1AzEq | ||
|
||
[![Scala Play React Seed](https://github.com/yohangz/scala-play-react-seed/blob/master/react.png)](http://bit.ly/2A1AzEq) | ||
|
||
## Version Summary | ||
|
||
* [Play Framework: 2.7.0](https://www.playframework.com/documentation/2.7.x/Home) | ||
* [React: 16.8.5](https://reactjs.org/) | ||
* [Create React App: 1.0.17](https://github.com/facebookincubator/create-react-app) | ||
|
||
## How to use it? | ||
|
||
### Prerequisites | ||
|
||
* [Node.js](https://nodejs.org/) | ||
* [scala](https://www.scala-lang.org/download/) | ||
|
||
### Let's get started, | ||
|
||
* Fork or clone this repository. | ||
|
||
* Used any of the following [SBT](http://www.scala-sbt.org/) commands which will intern trigger frontend associated npm scripts. | ||
|
||
``` | ||
sbt clean # Clean existing build artifacts | ||
sbt stage # Build your application from your project’s source directory | ||
sbt run # Run both backend and frontend builds in watch mode | ||
sbt dist # Build both backend and frontend sources into a single distribution artifact | ||
sbt test # Run both backend and frontend unit tests | ||
``` | ||
|
||
* This seed is not using [scala play views](https://www.playframework.com/documentation/2.6.x/ScalaTemplates). All the views and frontend associated routes are served via [React](https://reactjs.org/) code base under `ui` directory. | ||
|
||
## Complete Directory Layout | ||
|
||
``` | ||
├── /app/ # The backend (scala play) sources (controllers, models, services) | ||
│ └── /controllers/ # Backend controllers | ||
│ └── FrontendController.scala # Asset controller wrapper serving frontend assets and artifacts | ||
├── /conf/ # Configurations files and other non-compiled resources (on classpath) | ||
│ ├── application.conf # Play application configuratiion file. | ||
│ ├── logback.xml # Logging configuration | ||
│ └── routes # Routes definition file | ||
├── /logs/ # Log directory | ||
│ └── application.log # Application log file | ||
├── /project/ # Contains project build configuration and plugins | ||
│ ├── FrontendCommands.scala # Frontend build command mapping configuration | ||
│ ├── FrontendRunHook.scala # Forntend build PlayRunHook (trigger frontend serve on sbt run) | ||
│ ├── build.properties # Marker for sbt project | ||
│ └── plugins.sbt # SBT plugins declaration | ||
├── /public/ # Frontend build artifacts will be copied to this directory | ||
├── /target/ # Play project build artifact directory | ||
│ ├── /universal/ # Application packaging | ||
│ └── /web/ # Compiled web assets | ||
├── /test/ # Contains unit tests of backend sources | ||
├── /ui/ # React frontend source (based on Create React App) | ||
│ ├── /public/ # Contains the index.html file | ||
│ ├── /node_modules/ # 3rd-party frontend libraries and utilities | ||
│ ├── /src/ # The frontend source codebase of the application | ||
│ ├── .editorconfig # Define and maintain consistent coding styles between different editors and IDEs | ||
│ ├── .gitignore # Contains ui files to be ignored when pushing to git | ||
│ ├── package.json # NPM configuration of frontend source | ||
│ ├── README.md # Contains all user guide details for the ui | ||
│ └── yarn.lock # Yarn lock file | ||
├── .gitignore # Contains files to be ignored when pushing to git | ||
├── build.sbt # Play application SBT configuration | ||
├── LICENSE # License Agreement file | ||
├── README.md # Application user guide | ||
└── ui-build.sbt # SBT command hooks associated with frontend npm scripts | ||
``` | ||
|
||
## What is new in here? | ||
|
||
### FrontendCommands.scala | ||
|
||
* Frontend build command mapping configuration. | ||
|
||
``` | ||
├── /project/ | ||
│ ├── FrontendCommands.scala | ||
``` | ||
|
||
|
||
### FrontendRunHook.scala | ||
|
||
* PlayRunHook implementation to trigger ``npm run start`` on ``sbt run``. | ||
|
||
``` | ||
├── /project/ | ||
│ ├── FrontendRunHook.scala | ||
``` | ||
|
||
### FrontendController.scala | ||
|
||
* Asset controller wrapper serving frontend assets and artifacts. | ||
|
||
``` | ||
├── /app/ | ||
│ └── /controllers/ | ||
│ └── FrontendController.scala | ||
``` | ||
|
||
### ui-build.sbt | ||
|
||
* This file contains the build task hooks to trigger frontend npm scripts on sbt command execution. | ||
|
||
### npm run commands | ||
|
||
* New and modified npm scripts of [Create React App](https://github.com/facebookincubator/create-react-app) generated package.json. | ||
* Check [UI README.md](./ui/README.md) to see all available frontend build tasks. | ||
|
||
``` | ||
├── /ui/ | ||
│ ├── package.json | ||
``` | ||
|
||
## Routes | ||
|
||
``` | ||
├── /conf/ | ||
│ ├── routes | ||
``` | ||
|
||
* The following route configuration map index.html to entry route (root). This should be placed as the initial route. | ||
|
||
``` | ||
GET / controllers.FrontendController.index() | ||
``` | ||
|
||
* All API routes should be prefixed with API prefix defined under ``application.conf`` (Default prefix ``apiPrefix = "api"``) | ||
|
||
Example API route: | ||
|
||
``` | ||
GET /api/summary controllers.HomeController.appSummary | ||
``` | ||
|
||
* The following route is being used to serve frontend associated build artifacts (css, js) and static assets (images, etc.). This should be placed as the final route. | ||
|
||
``` | ||
GET /*file controllers.FrontendController.assetOrDefault(file) | ||
``` | ||
|
||
**Note: _On production build all the front end React build artifacts will be copied to the `public` folder._** | ||
|
||
## Can be used to implement any front end/ui build! | ||
|
||
* Simply replace the ui directory with the build of your choice | ||
* Make output directory ROOT/public/ | ||
* Implement a proxy to localhost:9000 | ||
|
||
## Looking for some other frontend framework or language choice | ||
|
||
* [Java Play React Seed](https://github.com/yohangz/java-play-react-seed) | ||
* [Scala Play Angular Seed](https://github.com/yohangz/scala-play-angular-seed) | ||
* [Java Play Angular Seed](https://github.com/yohangz/java-play-angular-seed) | ||
* [Scala Play Vuejs Seed](https://github.com/duncannevin/scala-play-vue-seed) by [Duncan Nevin](https://github.com/duncannevin) | ||
* [Java Play Vuejs Seed](https://github.com/duncannevin/java-play-vue-seed) by [Duncan Nevin](https://github.com/duncannevin) | ||
|
||
## Contributors | ||
|
||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
|[<img src="https://avatars2.githubusercontent.com/u/5279079?s=400&v=4" width="100px;"/><br /><sub>Yohan Gomez</sub>][yohan-profile]| [<img src="https://avatars2.githubusercontent.com/u/6312524?s=400&u=efc9267c6f903c379fafaaf7b3b0d9a939474c01&v=4" width="100px;"/><br /><sub>Lahiru Jayamanna</sub>][lahiru-profile]<br />| [<img src="https://avatars0.githubusercontent.com/u/3881403?s=400&v=4" width="100px;"/><br /><sub>Gayan Attygalla</sub>](https://github.com/Arty26)| | ||
| :---: | :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
|
||
## License | ||
|
||
This software is licensed under the MIT license | ||
|
||
[license-badge]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat | ||
[license]: https://github.com/yohangz/java-play-react-seed/blob/master/README.md | ||
|
||
[yohan-profile]: https://github.com/yohangz | ||
[lahiru-profile]: https://github.com/lahiruz | ||
[gayan-profile]: https://github.com/Arty26 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import com.google.inject.AbstractModule | ||
|
||
/** | ||
* This class is a Guice module that tells Guice how to bind several | ||
* different types. This Guice module is created when the Play | ||
* application starts. | ||
* Play will automatically use any class called `Module` that is in | ||
* the root package. You can create modules in other locations by | ||
* adding `play.modules.enabled` settings to the `application.conf` | ||
* configuration file. | ||
*/ | ||
class Module extends AbstractModule { | ||
|
||
override def configure() = { | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package controllers | ||
|
||
import javax.inject._ | ||
|
||
import play.api.libs.json.Json | ||
import play.api.mvc._ | ||
|
||
@Singleton | ||
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { | ||
|
||
def appSummary = Action { | ||
Ok(Json.obj("content" -> "Scala Play React Seed")) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name := """scala-play-react-seed""" | ||
|
||
version := "1.0-SNAPSHOT" | ||
|
||
lazy val root = (project in file(".")).enablePlugins(PlayScala).settings( | ||
watchSources ++= (baseDirectory.value / "public/ui" ** "*").get | ||
) | ||
|
||
resolvers += Resolver.sonatypeRepo("snapshots") | ||
|
||
scalaVersion := "2.12.8" | ||
|
||
libraryDependencies += guice | ||
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test | ||
libraryDependencies += "com.h2database" % "h2" % "1.4.196" |
Oops, something went wrong.