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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码