Last active
August 30, 2019 07:57
-
-
Save tobias-/cbdc441872d2256b1d7a318b54ae057e to your computer and use it in GitHub Desktop.
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
import com.linecorp.armeria.common.HttpMethod | |
import com.linecorp.armeria.common.HttpService | |
import com.linecorp.armeria.server.SimpleDecoratingHttpService | |
import com.linecorp.armeria.server.Service | |
import com.linecorp.armeria.server.cors.CorsService | |
import com.linecorp.armeria.server.cors.CorsServiceBuilder | |
import org.kodein.di.Kodein | |
import org.kodein.di.direct | |
import org.kodein.di.generic.instance | |
import java.util.function.Function | |
interface GrpcDecorator<T> : Function<HttpService, SimpleDecoratingHttpService> | |
@Suppress("UNCHECKED_CAST") | |
class GrpcWebCors(kodein: Kodein) : | |
GrpcDecorator<CorsService>, | |
Function<HttpService, SimpleDecoratingHttpService> | |
by | |
CorsServiceBuilder | |
.forOrigins( | |
"https://example.com" | |
) | |
.allowCredentials() | |
.allowNullOrigin() | |
.allowRequestMethods(HttpMethod.POST, HttpMethod.GET) | |
.allowRequestHeaders( | |
"authorization", | |
"content-type", | |
"x-grpc-web" | |
) | |
.exposeHeaders( | |
"grpc-message", | |
"grpc-status", | |
"x-server-version" | |
) | |
.newDecorator() as Function<HttpService, SimpleDecoratingHttpService> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kodein is the DI framework