diff --git a/build.gradle b/build.gradle index 68d80f1..71681e8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.kotlin_version = '1.2.0' ext { + kotlin_version = '1.2.41' springBootVersion = '2.0.0.M7' } repositories { @@ -9,17 +9,16 @@ buildscript { jcenter() } dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion") classpath('se.transmode.gradle:gradle-docker:1.2') - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" - classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0' + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version") + classpath('com.github.ben-manes:gradle-versions-plugin:0.17.0') } } group = 'dissem' -apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'kotlin-spring' apply plugin: 'eclipse' @@ -51,23 +50,24 @@ dependencies { compile("org.springframework.boot:spring-boot-starter-web") compile("io.springfox:springfox-swagger2:2.7.0") compile("io.springfox:springfox-swagger-ui:2.7.0") + compile("com.fasterxml.jackson.module:jackson-module-kotlin:") - compile "ch.dissem.jabit:jabit-core:$jabitVersion" - compile "ch.dissem.jabit:jabit-networking:$jabitVersion" - compile "ch.dissem.jabit:jabit-repositories:$jabitVersion" - compile "ch.dissem.jabit:jabit-cryptography-bouncy:$jabitVersion" - compile "ch.dissem.jabit:jabit-extensions:$jabitVersion" + compile("ch.dissem.jabit:jabit-core:$jabitVersion") + compile("ch.dissem.jabit:jabit-networking:$jabitVersion") + compile("ch.dissem.jabit:jabit-repositories:$jabitVersion") + compile("ch.dissem.jabit:jabit-cryptography-bouncy:$jabitVersion") + compile("ch.dissem.jabit:jabit-extensions:$jabitVersion") - compile 'com.h2database:h2:1.4.194' + compile('com.h2database:h2:1.4.194') - compile 'com.google.zxing:core:3.3.1' + compile('com.google.zxing:core:3.3.1') providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") testCompile("org.springframework.boot:spring-boot-starter-test") - compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" + compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version") + compile("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version") + compile("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") + compile("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version") } @@ -92,25 +92,24 @@ task buildDocker(type: Docker, dependsOn: build) { jar { baseName = 'jabit-server' +} + +//frontend:build will be run before processResources +processResources { + dependsOn('frontend:build') from('frontend/dist') { //Public is a default supported Spring Boot resources directory. into 'public' } } -//frontend:build will be run before the processResources -processResources.dependsOn('frontend:build') - task wrapper(type: Wrapper) { gradleVersion = '2.3' } + compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } + kotlinOptions.jvmTarget = "1.8" } compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } + kotlinOptions.jvmTarget = "1.8" } diff --git a/src/main/kotlin/ch/dissem/bitmessage/server/FrontendController.kt b/src/main/kotlin/ch/dissem/bitmessage/server/FrontendController.kt new file mode 100644 index 0000000..be75d7c --- /dev/null +++ b/src/main/kotlin/ch/dissem/bitmessage/server/FrontendController.kt @@ -0,0 +1,18 @@ +package ch.dissem.bitmessage.server + +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.RequestMapping +import javax.servlet.http.HttpServletRequest + + +@Controller +@RequestMapping +class FrontendController { + + @RequestMapping("/{path:[^\\.]+}/**") + fun redirect(request: HttpServletRequest): String { + // Also forward to home page so that route is preserved. + return "forward:/index.html" + } + +} \ No newline at end of file diff --git a/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerApplication.kt b/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerApplication.kt index 93406c5..3cff446 100644 --- a/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerApplication.kt +++ b/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerApplication.kt @@ -20,8 +20,10 @@ import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.context.annotation.ComponentScan import org.springframework.scheduling.annotation.EnableScheduling +import org.springframework.web.servlet.config.annotation.EnableWebMvc import springfox.documentation.swagger2.annotations.EnableSwagger2 +@EnableWebMvc @EnableSwagger2 @EnableScheduling @SpringBootApplication diff --git a/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerConfig.kt b/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerConfig.kt index b5f3665..4d52c16 100644 --- a/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerConfig.kt +++ b/src/main/kotlin/ch/dissem/bitmessage/server/JabitServerConfig.kt @@ -172,13 +172,13 @@ class JabitServerConfig { if (identities.isEmpty()) { LOG.info("Creating new identity...") identity = bitmessageContext().createIdentity(false, Pubkey.Feature.DOES_ACK) - LOG.info("Identity " + identity.address + " created.") + LOG.info("Identity ${identity.address} created.") } else { LOG.info("Identities:") identities.forEach { LOG.info(it.address) } identity = identities[0] if (identities.size > 1) { - LOG.info("Using " + identity) + LOG.info("Using $identity") } } LOG.info("QR Code:\n" + Utils.qrCode(identity)) diff --git a/src/main/kotlin/ch/dissem/bitmessage/server/WebMvcConfig.kt b/src/main/kotlin/ch/dissem/bitmessage/server/WebMvcConfig.kt new file mode 100644 index 0000000..0d8bf02 --- /dev/null +++ b/src/main/kotlin/ch/dissem/bitmessage/server/WebMvcConfig.kt @@ -0,0 +1,20 @@ +package ch.dissem.bitmessage.server + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + + +@Configuration +class WebMvcConfig : WebMvcConfigurer { + + override fun addResourceHandlers(registry: ResourceHandlerRegistry) { + if (!registry.hasMappingForPattern("/webjars/**")) { + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/") + } + if (!registry.hasMappingForPattern("/**")) { + registry.addResourceHandler("/**").addResourceLocations("classpath:/public/") + } + } + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 815acd7..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ -logging.file=jabit.log -logging.level.*=ERROR -logging.level.ch.dissem.*=WARN -bitmessage.port=8444 -bitmessage.connection.ttl.hours=12 -bitmessage.connection.limit=100 -database.url=jdbc:h2:file:./jabit;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=10 -database.user=sa -database.password= \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..3d596f1 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,16 @@ +#server.servlet.contextPath=/jabit-server +logging: + file: 'jabit.log' + level.*: ERROR + level.ch.dissem.*: WARN + +bitmessage: + port: 8444 + connection: + ttl.hours: 12 + limit: 100 + +database: + url: 'jdbc:h2:file:./jabit;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=10' + user: 'sa' + password: \ No newline at end of file diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties deleted file mode 100644 index fb4aa02..0000000 --- a/src/test/resources/application.properties +++ /dev/null @@ -1,7 +0,0 @@ -logging.file=jabit.log -logging.level.*=DEBUG -logging.level.ch.dissem.*=DEBUG -bitmessage.port=18444 -database.url=jdbc:h2:mem:jabit;DB_CLOSE_DELAY=10 -bitmessage.connection.ttl.hours=12 -bitmessage.connection.limit=100 diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..39de808 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,15 @@ +logging: + file: 'jabit.log' + level.*: DEBUG + level.ch.dissem.*: DEBUG + +bitmessage: + port: 18444 + connection: + ttl.hours: 12 + limit: 100 + +database: + url: 'jdbc:h2:mem:jabit;DB_CLOSE_DELAY=10' + user: sa + password: