【发布时间】:2020-09-27 05:37:57
【问题描述】:
我遇到了这段代码,想在端口 1111、1112 和 1113 上允许 CORS,我该怎么做?
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/all", All).Methods("GET")
router.HandleFunc("/gotoT", Goto).Methods("GET")
headers := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"})
methods := handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS"})
origins := handlers.AllowedOrigins([]string{"*"})
log.Fatal(http.ListenAndServe(":1111", handlers.CORS(headers, methods, origins)(router)))
在这个例子中,CORS 只监听端口 1111,所以我想添加更多端口,请帮忙?
【问题讨论】:
-
在本例中,http-server 正在监听端口 1111。您希望同一台服务器同时在不同端口上运行吗?也许端口转发是一个更好的主意。