简体   繁体   English

客户端与 angular 中的 unix 套接字

[英]client side with unix socket in angular

created server app with unix socket in golang在 golang 中使用 unix 套接字创建了服务器应用程序

server app code:服务器应用程序代码:

package main
import (
  "fmt"
  "net"
  "net/http"
  "os"
)
func main() {
  sock := "/var/web.sock"
  err := os.Remove(sock)
  if err != nil {
    fmt.Printf("Can not remove socket config file.")
  }
  unixListener, err := net.Listen("unix", sock)
  if err != nil {
    fmt.Printf("Can not create unix socket listener,")
  }
  http.HandleFunc("/3dviewer/upload", uploadFile)
  http.Serve(unixListener, nil)
}
func uploadFile(w http.ResponseWriter, r *http.Request) {
   fmt.Printf("WORKING") 
}

need client side angular code to connect to server app.需要客户端 angular 代码来连接到服务器应用程序。 please some one can help me.请有人可以帮助我。

Thanks in advance提前致谢

You can use reverse proxy such as Nginx to handle Angular HTTP/HTTPS call, and forward to the Unix Socket您可以使用Nginx等反向代理来处理Angular HTTP/HTTPS调用,并转发到Unix Socket

In case of you use nginx, you can create a configuration at /etc/nginx/site-available/your_configuration_file如果您使用 nginx,您可以在/etc/nginx/site-available/your_configuration_file创建配置

Then enable it by然后通过

sudo ln -s /etc/nginx/sites-available/your_configuration_file /etc/nginx/sites-enabled/

An example for the Nginx configuration file Nginx 配置文件示例

server {
    listen 80;
    server_name server_domain_or_IP;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/myproject/myproject.sock;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM