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
329d13e
commit a8b3a58
Showing
13 changed files
with
200 additions
and
5 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 @@ | ||
.classpath |
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,4 @@ | ||
target | ||
.settings | ||
.project | ||
.classpath |
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
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,32 @@ | ||
package com.tmp; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@EnableWebMvc | ||
@SpringBootApplication | ||
public class App implements ApplicationListener<ContextRefreshedEvent> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(App.class); | ||
|
||
@Value("${spring.profiles.active}") | ||
protected String springProfilesActive; | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
LOG.info("======================================="); | ||
LOG.info("App running with active profiles: {}", springProfilesActive); | ||
LOG.info("======================================="); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(App.class, args); | ||
} | ||
|
||
} |
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,45 @@ | ||
package com.tmp; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
@RequestMapping(value = "/api/greetings") | ||
public class GreeterController { | ||
|
||
private static final String template = "Hello, %s!"; | ||
|
||
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }) | ||
public @ResponseBody Greeting greetNoName() { | ||
return new Greeting(String.format(template, "World")); | ||
} | ||
|
||
@RequestMapping(value = "/{name}", method = RequestMethod.GET, produces = { "application/json" }) | ||
public @ResponseBody Greeting greetName(final @PathVariable String name) { | ||
return new Greeting(String.format(template, name)); | ||
} | ||
|
||
public class Greeting { | ||
private final String content; | ||
private final LocalDateTime time; | ||
|
||
public Greeting(String content) { | ||
this.content = content; | ||
this.time = LocalDateTime.now(); | ||
} | ||
|
||
public String getContent() { | ||
return this.content; | ||
} | ||
|
||
public String getTime() { | ||
return this.time.toString(); | ||
} | ||
} | ||
|
||
} |
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,46 @@ | ||
package com.tmp; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
public class WebMvcConfig extends WebMvcConfigurerAdapter { | ||
|
||
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/public/" }; | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
super.addResourceHandlers(registry); | ||
if (!registry.hasMappingForPattern("/webjars/**")) { | ||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); | ||
} | ||
if (!registry.hasMappingForPattern("/**")) { | ||
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS); | ||
} | ||
} | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.addViewController("/").setViewName("forward:/index.html"); | ||
} | ||
|
||
// During development, webpack server runs on localhost:8080 | ||
// Make the browser happy by returning CORS headers in this case | ||
@Bean | ||
@Profile("dev") | ||
public WebMvcConfigurer corsConfigurer() { | ||
return new WebMvcConfigurerAdapter() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/api/**").allowedOrigins("http://localhost:8080"); | ||
} | ||
}; | ||
} | ||
|
||
} |
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,2 @@ | ||
spring.profiles.active=dev | ||
server.port=8090 |
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,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>App</title> | ||
</head> | ||
<body> | ||
|
||
<script src="/webjars/fe/0.0.1-SNAPSHOT/app-bundle.js"></script> | ||
</body> | ||
</html> |
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,4 @@ | ||
node | ||
node_modules | ||
target | ||
etc |
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
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,11 +1,15 @@ | ||
{ | ||
"name": "fe", | ||
"version": "1.0.0", | ||
"version": "0.0.1-SNAPSHOT", | ||
"description": "", | ||
"main": "./app", | ||
"scripts": { | ||
"build": "webpack -p" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"devDependencies": { | ||
"webpack": "1.12.9", | ||
"webpack-dev-server": "1.14.0" | ||
} | ||
} |
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,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>App</title> | ||
</head> | ||
<body> | ||
|
||
<script src="../assets/app-bundle.js"></script> | ||
</body> | ||
</html> |
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