Start fleshing out serving assets and the FE side of the app

This commit is contained in:
R. Tyler Croy 2015-06-01 06:49:06 -07:00
parent 2cb37364c0
commit ecfa66e6f5
9 changed files with 119 additions and 13 deletions

View File

@ -1,8 +1,21 @@
plugins {
id 'groovy'
id 'application'
id 'codenarc'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.1"
//classpath 'com.prezi.typescript:gradle-typescript-plugin:2.2.5'
classpath 'de.richsource.gradle.plugins:typescript-gradle-plugin:1.1'
}
}
apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: 'codenarc'
apply plugin: 'typescript'
apply plugin: "com.github.johnrengelman.shadow"
description = 'Offtopic is for watching Kafka topics'
mainClassName = 'offtopic.OfftopicApp'
@ -13,7 +26,12 @@ repositories {
dependencies {
compile "org.codehaus.groovy:groovy:${groovyVersion}"
compile "io.dropwizard:dropwizard-core:${dropwizardVersion}"
['core', 'assets', 'views', 'views-mustache'].each {
compile "io.dropwizard:dropwizard-${it}:${dropwizardVersion}"
}
compile 'joda-time:joda-time:2.6+'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'cglib:cglib-nodep:2.2.+'
@ -36,3 +54,20 @@ codenarc {
run {
args 'server', 'offtopic.example.yml'
}
shadowJar {
exclude 'META-INF/*.RSA', 'META-INF/*.DSA'
manifest {
attributes 'Main-Class' : mainClassName
}
// Only run after we've successfully completed our tests
dependsOn check
}
assemble.dependsOn shadowJar
compileTypeScript {
sourcemap = true
out = file("${buildDir}/js/offtopic.js")
}
processResources.dependsOn compileTypeScript

View File

@ -6,4 +6,4 @@ group=com.github.rtyler
dropwizardVersion=0.8.1
groovyVersion=2.4.3
org.gradle.daemon=true
org.gradle.daemon=false

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="offtopic" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="offtopic" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.github.rtyler" external.system.module.version="0.3.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
@ -95,5 +95,14 @@
<orderEntry type="library" exported="" name="Gradle: org.glassfish.hk2.external:aopalliance-repackaged:2.4.0-b10" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.javassist:javassist:3.18.1-GA" level="project" />
<orderEntry type="library" exported="" name="Gradle: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" exported="" name="Gradle: io.dropwizard:dropwizard-assets:0.8.1" level="project" />
<orderEntry type="library" exported="" name="Gradle: io.dropwizard:dropwizard-views-mustache:0.8.1" level="project" />
<orderEntry type="library" exported="" name="Gradle: io.dropwizard:dropwizard-views:0.8.1" level="project" />
<orderEntry type="library" exported="" name="Gradle: com.github.spullara.mustache.java:compiler:0.8.17" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.spockframework:spock-core:0.7-groovy-2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: cglib:cglib-nodep:2.2.2" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit-dep:4.10" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.codehaus.groovy:groovy-all:2.0.5" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

View File

@ -1,11 +1,17 @@
package offtopic
import com.google.common.collect.ImmutableMap
import io.dropwizard.Application
import io.dropwizard.Bundle
import io.dropwizard.setup.Bootstrap
import io.dropwizard.setup.Environment
import groovy.transform.TypeChecked
import io.dropwizard.assets.AssetsBundle
import io.dropwizard.views.ViewBundle
import groovy.transform.TypeChecked
import offtopic.resources.MainResource
import org.joda.time.DateTimeZone
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -33,6 +39,7 @@ class OfftopicApp extends Application<OfftopicConfig> {
this.logger.info("Starting the Offtopic application")
environment.healthChecks().register('sanity', new offtopic.health.BasicHealth())
environment.jersey().register(new MainResource())
}
@Override
@ -43,5 +50,21 @@ class OfftopicApp extends Application<OfftopicConfig> {
@Override
void initialize(Bootstrap<OfftopicConfig> bootstrap) {
this.logger.info("Initializing application")
bootstrap.addBundle(new AssetsBundle('/assets/', '/assets'))
bootstrap.addBundle(new ViewBundle<OfftopicConfig>() {
@Override
ImmutableMap<String, ImmutableMap<String, String>> getViewConfiguration(OfftopicConfig config) {
return config.viewRendererConfiguration
}
} as Bundle)
/*
* Force our default timezone to always be UTC
*/
DateTimeZone.setDefault(DateTimeZone.UTC)
logger.info("Set default timezone to UTC")
}
}

View File

@ -1,9 +1,14 @@
package offtopic
import com.fasterxml.jackson.annotation.JsonProperty
import com.google.common.collect.ImmutableMap
import io.dropwizard.Configuration
/**
*
*/
class OfftopicConfig extends Configuration{
class OfftopicConfig extends Configuration {
@JsonProperty
private ImmutableMap<String, ImmutableMap<String, String>> \
viewRendererConfiguration = ImmutableMap.of()
}

View File

@ -1,8 +1,24 @@
package offtopic.resources
/**
*
*/
@SuppressWarnings('EmptyClass')
import com.codahale.metrics.annotation.Timed
import com.google.common.base.Charsets
//import io.dropwizard.jersey.caching.CacheControl
import io.dropwizard.views.View
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import java.util.concurrent.TimeUnit
@Path("/")
@Produces(MediaType.TEXT_HTML)
class MainResource {
@GET
@Timed(name = "get-requests")
//@CacheControl(maxAge = 0, maxAgeUnit = TimeUnit.DAYS)
public View responder() {
return new View('/views/index.mustache', Charsets.UTF_8) { }
}
}

View File

@ -0,0 +1 @@
../../../../build/js

View File

@ -0,0 +1,5 @@
Hello World, you look nice today
You should have a drink?
Let's listen to music!

12
src/main/ts/Main.ts Normal file
View File

@ -0,0 +1,12 @@
interface Person {
firstname: string;
lastname: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstname + " " + person.lastname;
}
var user = {firstname: "Jane", lastname: "User"};
document.body.innerHTML = greeter(user);