umi-react + golang 开发部署

umi自有路由,golang也有路由,冲突了,这么解决:

func listenAndProcessWeb() {
       http.Handle("/static", http.FileServer(http.Dir("zzpages/static")))
       http.HandleFunc("/", ReactPages)
}

func ReactPages(w http.ResponseWriter, r *http.Request) {
       t, _ := template.ParseFiles("zzpages/index.html")
       t.Execute(w, nil)
}

umi-react + golang 开发部署_第1张图片

umi-react + golang 开发部署_第2张图片

 

如果报错: 

Uncaught SyntaxError: Unexpected token <

或者:

 MIME type ('text/html') is not executable, and strict MIME type checking is enable

估计是golang 跟nginx监听冲突了

nginx的web路径:/usr/local/nginx/html

 

可以直接把umi-dva编译打包的文件直接丢这里也行,打包可以选择生成静态的。

umi-react + golang 开发部署_第3张图片

 

你可能感兴趣的:(umi-react + golang 开发部署)