Skip to content

Commit 65c83e1

Browse files
committed
fix all shit
1 parent 130bb85 commit 65c83e1

File tree

6 files changed

+41
-28
lines changed

6 files changed

+41
-28
lines changed

build.gradle

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
buildscript {
2-
repositories { jcenter() }
3-
dependencies {
4-
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE"
5-
}
1+
plugins {
2+
id "java"
3+
id "idea"
4+
id "org.springframework.boot" version "1.5.7.RELEASE"
65
}
76

8-
apply plugin: 'java'
9-
apply plugin: 'idea'
10-
apply plugin: 'spring-boot'
11-
127
jar {
13-
baseName = 'server-side-react-spring-boot'
14-
version = '0.0.1'
8+
baseName = "server-side-react-spring-boot"
9+
version = "0.0.1"
1510
}
1611

1712
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -20,25 +15,26 @@ targetCompatibility = JavaVersion.VERSION_1_8
2015
repositories { jcenter() }
2116

2217
dependencies {
23-
compile 'org.springframework.boot:spring-boot-starter-actuator',
24-
'org.springframework.boot:spring-boot-starter-mustache',
25-
'org.springframework.boot:spring-boot-starter-data-rest',
26-
'org.springframework.boot:spring-boot-starter-data-jpa',
27-
'org.springframework.boot:spring-boot-devtools',
28-
'org.projectlombok:lombok'
29-
runtime 'com.h2database:h2'
30-
testCompile 'org.springframework.boot:spring-boot-starter-test'
18+
compile "org.springframework.boot:spring-boot-starter-actuator",
19+
"org.springframework.boot:spring-boot-starter-mustache",
20+
"org.springframework.boot:spring-boot-starter-data-rest",
21+
"org.springframework.boot:spring-boot-starter-data-jpa",
22+
"org.springframework.boot:spring-boot-devtools",
23+
"org.projectlombok:lombok"
24+
runtime "com.h2database:h2"
25+
testCompile "org.springframework.boot:spring-boot-starter-test"
3126
}
3227

3328
task ui(type: Exec) {
34-
workingDir './ui'
29+
workingDir "$projectDir/ui"
3530
commandLine "npm", "run", "build"
3631
}
3732

38-
build.shouldRunAfter ui
33+
assemble.shouldRunAfter ui
3934

4035
task wrapper(type: Wrapper) {
41-
gradleVersion = '3.0'
36+
gradleVersion = "4.2.1"
37+
distributionType = "ALL"
4238
}
4339

4440
// bash build/libs/*.jar

src/main/java/daggerok/react/ReactServerSideRenderingController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public ReactServerSideRenderingController(React react,
2626
this.objectMapper = objectMapper;
2727
}
2828

29-
@GetMapping("/")
3029
@SneakyThrows
30+
@GetMapping({"/", "/404", "/not-found"})
3131
public String index(Model model) {
3232
val posts = postRestRepository.findAll();
3333
model.addAttribute("data", react.renderApp(posts));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package daggerok.web;
2+
3+
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
4+
import org.springframework.boot.web.servlet.ErrorPage;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
import static org.springframework.http.HttpStatus.NOT_FOUND;
9+
10+
@Configuration
11+
public class FallbackConfig {
12+
13+
@Bean
14+
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {
15+
return container -> container.addErrorPages(
16+
new ErrorPage(NOT_FOUND, "/404")
17+
);
18+
}
19+
}

src/main/java/daggerok/web/FallbackHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Created by mak on 9/7/16.
1919
*/
2020
@Slf4j
21-
@Controller
21+
//@Controller
2222
@RequiredArgsConstructor
2323
public class FallbackHandler implements ErrorController {
2424

src/main/resources/templates/index.hbs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<link href="{{springMacroRequestContext.request.contextPath}}/app.css" rel="stylesheet"></head>
88
<body class="container">
99
<!-- 1) render data from backend server side (see daggerok.react.ReactServerSideRenderingController.index) -->
10-
<div id="app">{{{html}}}</div>
10+
<div id="app">{{{data}}}</div>
11+
<div id="app">{{{posts}}}</div>
1112
<script src="{{springMacroRequestContext.request.contextPath}}/app.js"></script>
1213
<!-- 2) up and running dynamic part of application after it static initial page was loader -->
1314
<script type="text/javascript">

ui/src/main.js

-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,3 @@ global.renderServer = function(java) {
5252
// console.log('server posts', posts);
5353
return renderToString(<App><Main posts={posts}/></App>);
5454
};
55-
56-
import $ from 'jquery';
57-
window.$ = $;

0 commit comments

Comments
 (0)