Coder Social home page Coder Social logo

Comments (5)

gdong42 avatar gdong42 commented on June 29, 2024

What was the error? How should I reproduce it. I can interact with grpc-mate by browser with no problem.

from grpc-mate.

Paxa avatar Paxa commented on June 29, 2024

Create simple http server on same host, and type fetch('http://127.0.0.1:6600/actuator/services')
Error will be something like this

Access to fetch at 'http://127.0.0.1:6600/actuator/services' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Screen Shot 2020-05-16 at 22 20 46

Having option to set Access-Control-Allow-Origin: * will be nice
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

from grpc-mate.

gdong42 avatar gdong42 commented on June 29, 2024

I see. So you are requesting /actuator/services using JavaScript, probably from a web UI running on other origin. It's not supported yet, but I think I can add it as an option. Is it needed for /v1/.. endpoints that are proxied to the backend gRPC server?

from grpc-mate.

gdong42 avatar gdong42 commented on June 29, 2024

There is a plan to add Web UI support: #8

Hopefully when it's done folks don't have to enable Access-Control headers and build a web UI theirselves. But for now, let me add an ACCESS_CONTROL_ALLOW_ORIGIN env option to set the response header.

from grpc-mate.

Paxa avatar Paxa commented on June 29, 2024

I'm building some UI for generating documentation and sending requests (similar to openapi)
The challenge so far to get all proto details because grpc.reflection.v1alpha.ServerReflection uses bi-directional streaming, which is not supported by grpc-mate

Btw any plans to support multiple backends?

As workaround I built grpc service to serve all protos as json

syntax = "proto3";
package internal;

option go_package = "protos";

service DescriptorServer { // after service
    rpc getAll(DescriptorsRequest) returns (DescriptorsResponse) {} // ta ta ta
}

message DescriptorsRequest {
}

message DescriptorsResponse {
    repeated string file = 1; // just one
}

go server

import (
	"context"
	pb "grpc-reflector/protos"

	"github.com/gogo/protobuf/jsonpb"
	log "github.com/sirupsen/logrus"
)

type DescriptorServer struct {
    pb.UnimplementedDescriptorServerServer
}

// be careful with output, it may break your terminal
func (s *DescriptorServer) GetAll(ctx context.Context, in *pb.DescriptorsRequest) (*pb.DescriptorsResponse, error) {
    all := []string{}
    m := jsonpb.Marshaler{}
    for _, descriptor := range CompiledProtos {
        compiled, err := m.MarshalToString(descriptor)
        if err == nil {
            all = append(all, compiled)
        } else {
            log.Errorf("Can not compile %v", err)
        }
    }
    return &pb.DescriptorsResponse{File: all}, nil
}

It serve protos encoded as json string, in this way I don't need to do any protobuf decoding in JS

Will share some preview when it's usable

from grpc-mate.

Related Issues (10)

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.