mraible / cloud-native-pwas Goto Github PK
View Code? Open in Web Editor NEWCloud Native Progressive Web Apps with Spring Boot and Angular
Home Page: https://speakerdeck.com/mraible/building-cloud-native-progressive-web-apps-devoxx-morocco-2017
Cloud Native Progressive Web Apps with Spring Boot and Angular
Home Page: https://speakerdeck.com/mraible/building-cloud-native-progressive-web-apps-devoxx-morocco-2017
There's no docs on how to enable CORS with WebFlux, and this question/answer on Stack Overflow doesn't link to anything useful.
This works with kotlin-basic, but not kotlin-reactive:
class EdgeServiceApplication {
@Bean
fun simpleCorsFilter(): FilterRegistrationBean<CorsFilter> {
val source = UrlBasedCorsConfigurationSource()
val config = CorsConfiguration()
config.allowCredentials = true
config.allowedOrigins = listOf("http://localhost:4200")
config.allowedMethods = listOf("*");
config.allowedHeaders = listOf("*")
source.registerCorsConfiguration("/**", config)
val bean = FilterRegistrationBean(CorsFilter(source))
bean.order = Ordered.HIGHEST_PRECEDENCE
return bean
}
}
Steps to reproduce:
Start all server-side services:
mvn -f beer-catalog-service/pom.xml spring-boot:run
mvn -f edge-service/pom.xml spring-boot:run
mvn -f eureka-service/pom.xml spring-boot:run
Hit http://localhost:8081/good-beers with your browser or httpie. I'd expect access denied, but I'm allowed to see the data with no Stormpath security invoked.
The edge-service project has the Stormpath dependency:
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-zuul-spring-cloud-starter</artifactId>
<version>1.2.2</version>
</dependency>
As well as the necessary SecurityConfiguration.java
:
package com.example;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.apply(stormpath()).and()
.authorizeRequests()
.antMatchers("/**").permitAll();
}
}
And the property to forward requests in application.properties
:
server.use-forward-headers=true
The last property shouldn't be needed because /good-beers
is an API on the gateway. To access the other service -- /beers-catalog-service
-- this property seems to be needed.
On startup, the following message is printed to the console:
2017-11-04 10:56:00.724 INFO 73483 --- [localhost:27017] org.mongodb.driver.cluster :
Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.AsynchronousSocketChannelStream$OpenCompletionHandler
.failed(AsynchronousSocketChannelStream.java:254) ~[mongodb-driver-core-3.5.0.jar:na]
at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:128) ~[na:1.8.0_144]
at sun.nio.ch.Invoker$2.run(Invoker.java:218) ~[na:1.8.0_144]
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_144]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:252) ~[na:1.8.0_144]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198) ~[na:1.8.0_144]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213) ~[na:1.8.0_144]
at sun.nio.ch.KQueuePort$EventHandlerTask.run(KQueuePort.java:301) ~[na:1.8.0_144]
... 1 common frames omitted
I was able to fix it by following the steps in this article:
https://dzone.com/articles/spring-boot-with-embedded-mongodb
Add dependencies to pom.xml
:
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>1.50.5</version>
</dependency>
<dependency>
<groupId>cz.jirutka.spring</groupId>
<artifactId>embedmongo-spring</artifactId>
<version>RELEASE</version>
</dependency>
Create a src/main/kotlin/com/example/beercatalogservice/MongoConfig.kt
class:
package com.example.beercatalogservice
import java.io.IOException
import cz.jirutka.spring.embedmongo.EmbeddedMongoFactoryBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.mongodb.core.*
@Configuration
class MongoConfig {
@Bean
@Throws(IOException::class)
fun mongoTemplate(): MongoTemplate {
val mongo = EmbeddedMongoFactoryBean()
mongo.setBindIp(MONGO_DB_URL)
val mongoClient = mongo.getObject()
return MongoTemplate(mongoClient, MONGO_DB_NAME)
}
companion object {
private val MONGO_DB_URL = "localhost"
private val MONGO_DB_NAME = "embeded_db"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.