Docker Vuejs客户端可以';t通过MacOS上的gRPC与Go后端通信

Docker Vuejs客户端可以';t通过MacOS上的gRPC与Go后端通信,docker,vue.js,go,grpc,envoyproxy,Docker,Vue.js,Go,Grpc,Envoyproxy,我使用gRPC和protobuf构建了一个简单的web应用程序,其中包含一个VueJS前端(客户端)和一个返回(服务器)。 为了进行通信,必须在它们之间设置特使代理,以将web客户端HTTP/1.1转换为HTTP/2。 我在Linux上部署这个应用程序没有问题,并且已经对接了所有三个服务 但是,我无法让我的服务在MacOS上通信 应用程序存储库位于以下位置: deploy文件夹包含docker compose文件、特使容器所需的embassenger.yaml文件以及所有三个DockerFile

我使用gRPC和protobuf构建了一个简单的web应用程序,其中包含一个VueJS前端(客户端)和一个返回(服务器)。 为了进行通信,必须在它们之间设置特使代理,以将web客户端HTTP/1.1转换为HTTP/2。 我在Linux上部署这个应用程序没有问题,并且已经对接了所有三个服务

但是,我无法让我的服务在MacOS上通信

应用程序存储库位于以下位置:

deploy文件夹包含docker compose文件、特使容器所需的embassenger.yaml文件以及所有三个DockerFile。 在MacOS上,需要更新特使.yaml的最后一行,
localhost
必须更改为
host.docker.internal

客户端包含ping函数(在client/src/App.vue中),window.location.hostname可能需要更改为docker机器IP,对此不确定,我的尝试没有任何区别:

    created () {
        this.client = new NpuzzleClient('http://' + window.location.hostname + ':8080', null, null);
        const ping = () => {
            let message = new Message();
            message.setMessage('ping');
            this.client.greets(message, {}, err => this.serverOnline = !err);
        };
        ping();
        window.setInterval(ping, 1000);
    },
每秒执行一次,并在右上角显示服务器处于联机状态。到目前为止,我在MacOS上部署时未成功访问服务器。它在Linux上运行得非常好

这是go服务器的代码,我认为在localhost:9090上侦听是正确的,因为服务器将被停靠,但我可能错了,地址可能需要更改

package main

import (
    "context"
    "flag"
    "fmt"
    pb "github.com/42Projects/nPuzzle/proto"
    npuzzle "github.com/42Projects/nPuzzle/src"
    "google.golang.org/grpc"
    "log"
    "net"
    "time"
)

var port = flag.Int("port", 9090, "the server port")

type server struct{}

func (s *server) Greets(ctx context.Context, message *pb.Message) (*pb.Message, error) {

    return &pb.Message{Message: "pong!"}, nil
}

func (s *server) Parse(ctx context.Context, message *pb.Message) (*pb.Matrix, error) {

    log.Printf("received parsing request: %#v", message.Message)
    m, err := npuzzle.ParseMatrix(message.Message)
    if err != nil {
        log.Println(err)
        return &pb.Matrix{
            Success: false,
            Error:   err.Error(),
        }, nil
    }

    rows := make([]*pb.Matrix_Row, len(m))
    for index, row := range m {

        /* We need unsigned 32bits integer for protobuf */
        uIntRow := make([]uint32, len(m))
        for rowIndex, num := range row {
            uIntRow[rowIndex] = uint32(num)
        }

        rows[index] = &pb.Matrix_Row{Num: uIntRow}
    }

    return &pb.Matrix{
        Success: true,
        Rows:    rows,
    }, nil
}

func (s *server) Solve(ctx context.Context, problem *pb.Problem) (*pb.Result, error) {

    /* Choose heuristic function */
    var heuristic npuzzle.Heuristic
    switch problem.Heuristic {
    case "hamming":
        heuristic = npuzzle.HammingDistance
    case "manhattan":
        heuristic = npuzzle.ManhattanDistance
    case "manhattan + linear conflicts":
        heuristic = npuzzle.ManhattanPlusLinearConflicts
    }

    /* Choose between greedy search and uniform-cost search */
    var goal npuzzle.Goal
    var search npuzzle.Search
    switch problem.Search {
    case "greedy":
        goal = npuzzle.GreedyGoalReached
        search = npuzzle.GreedySearch
    case "uniform-cost":
        goal = npuzzle.UniformCostGoalReached
        search = npuzzle.UniformCostSearch
    }

    /* Convert protobuf unsigned 32bits integer to regular integer */
    size := len(problem.Rows)
    m := make(npuzzle.Matrix, size)
    for y, row := range problem.Rows {
        m[y] = make([]int, size)
        for x, num := range row.Num {
            m[y][x] = int(num)
        }
    }

    log.Printf("received problem:\n - heuristic: %v\n - search: %v\n - matrix: %v\n", problem.Heuristic, problem.Search, m)
    if npuzzle.IsSolvable(m) == false {
        log.Println("failed to solve problem: unsolvable")
        return &pb.Result{
            Success: false,
            Error:   "unsolvable",
        }, nil
    }

    begin := time.Now()
    log.Printf("starting solve on %v...", m)
    res, totalNumberOfStates, maxNumberOfStates, err := m.Solve(heuristic, search, goal, 30*time.Second)
    if err != nil {
        log.Printf("timed ouf after %v", 30*time.Second)
        return &pb.Result{
            Success: false,
            Error:   fmt.Sprintf("timed ouf after %v", 30*time.Second),
        }, nil
    }

    duration := time.Since(begin)
    log.Printf("solved %v in %v seconds", m, duration)
    var path string
    if res.Parent == nil {
        path = "already solved!"
    } else {
        path = npuzzle.StringifyPath(res)
    }

    return &pb.Result{
        Success:     true,
        Time:        duration.String(),
        Moves:       int32(res.Cost),
        TotalStates: int32(totalNumberOfStates),
        MaxStates:   int32(maxNumberOfStates),
        Path:        path,
    }, nil
}

func main() {

    flag.Parse()
    lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port))
    if err != nil {
        log.Fatalf("failed to listen: %v\n", err)
    }

    s := grpc.NewServer()
    pb.RegisterNpuzzleServer(s, &server{})
    log.Printf("starting server on port %v\n", *port)
    log.Fatalf("failed to serve: %v\n", s.Serve(lis))
}
我尝试在本地启动客户机和服务器,只将特使代理封装起来,同时尝试不同的地址(我的docker机器IP地址和本地主机),但没有成功。我也试着启动所有三个容器,但在这里也没有结果。
我不确定如何更改才能成功地使我的应用程序在MacOS上正常工作。

您做过集成测试吗?你确定你的grpc工作正常吗?它在Linux上工作得很好,我只在mac上有这个问题。我会先检查防火墙。除此之外。。。耸耸肩