GithubHelp home page GithubHelp logo

mraible / cloud-native-pwas Goto Github PK

View Code? Open in Web Editor NEW
31.0 6.0 7.0 1.29 MB

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

Shell 40.24% Batchfile 27.78% Java 0.54% TypeScript 14.88% JavaScript 2.29% HTML 1.74% CSS 0.26% Groovy 1.43% Kotlin 10.83%
spring-boot spring-cloud netflix-eureka netflix-zuul angular progressive-web-app cloud-foundry

cloud-native-pwas's Issues

Document how to enable CORS with WebFlux

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
    }
}

Stormpath Zuul Config doesn't prevent access to API

Steps to reproduce:

  1. 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
    
  2. 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.

kotlin-reactive/beer-catalog-service doesn't start w/o MongoDB configured

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"
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.