Solon v3.2.1

网关的跨域处理参考

</> markdown

可以直接使用 solon-web-cors 插件的能力。

@Component(index = -99)
public class CloudGatewayCorsFilter implements CloudGatewayFilter {
    private CrossHandler crossHandler = new CrossHandler();

    @Override
    public Completable doFilter(ExContext ctx, ExFilterChain chain) {
        Context ctx2 = ctx.toContext();

        try {
            crossHandler.handle(ctx2);

            if (ctx2.getHandled()) {
                return Completable.complete();
            } else {
                return chain.doFilter(ctx);
            }
        } catch (Throwable ex) {
            return Completable.error(ex);
        }
    }
}