douran7929 2013-12-30 02:39 采纳率: 100%
浏览 63

Angular并在heroku上运行

I am trying to put my app on Heroku. I am using angular on the front-end and Go on the backend.

I followed this tutorial http://mmcgrana.github.io/2012/09/getting-started-with-go-on-heroku.html

However, when I go to the domain of my heroku app, I get the directory of my app (everything in the git). When I navigate to the /app folder, (where my angular app lives) it shows the app.

I don't want my app to be at

foobar.herokuapp.com/app/#/

I want it to be at

foobar.herokuapp.com

A simplified version of my app directory is:

foobar
 - /app
 - /server/server.go
 - .godir             // contains "app"
 - Procfile           // contains "web: server"

I ran "go get" from inside my /server folder

These work:

$ PORT=5000 demoapp

$ curl -i http://127.0.0.1:5000/

Here is my simple server.go

package main

import (
"github.com/gorilla/handlers"
"log"
"net/http"
"os"
)

func main() {
log.Println("Starting Server")
http.Handle("/", logHandler(http.FileServer(http.Dir("../app/"))))

log.Println("Listening...")
panic(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}

func logHandler(h http.Handler) http.Handler {
return handlers.LoggingHandler(os.Stdout, h)

}

  • 写回答

1条回答 默认 最新

  • dongnai6973 2014-01-10 14:26
    关注

    Changing your FileServer directory from "../app/" to "app/" (relative) or "/app/app/" (absolute) should solve the issue.

    http.Handle("/", logHandler(http.FileServer(http.Dir("app/"))))
    

    Your project root is the work folder when Heroku executes the Procfile command. It has the absolute path /app which is why ../app brings you back to your project root.

    Although your server.go is stored in the ./server subfolder it is still compiled into the project root with package main.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大