Skip to content

Commit

Permalink
build: use devweb
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Rooth committed Jul 28, 2014
1 parent b436ea8 commit 21c371e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin
/prox.exe
/Godeps/_workspace/github.com/coreos-inc/bridge
/frontend/public/bower_components
/frontend/public/dist
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ Update existing backend dependencies:
1. `go get -u foo/bar` as usual
1. `godep update foo/bar`

Run the dev server (auto-loads new code changes):
`./devweb`

### Dependencies
- nodejs glup
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ fi

eval $(go env)

go install github.com/coreos-inc/$PROJECT_DIR/server
go install github.com/coreos-inc/$PROJECT_DIR
12 changes: 12 additions & 0 deletions dev/dev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"github.com/coreos-inc/bridge/Godeps/_workspace/src/github.com/coreos/devweb/slave"

"github.com/coreos-inc/bridge/server"
)

func main() {
server.Handle()
slave.Main()
}
6 changes: 6 additions & 0 deletions devweb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

source build

go install github.com/coreos/devweb
PATH=$PATH:$PWD ./bin/devweb -addr :9000 github.com/coreos-inc/bridge/dev
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"log"
"net/http"
"os"

"github.com/coreos-inc/bridge/server"
)

var (
listenAddress string
)

func main() {
server.Handle()

listenAddress = os.Getenv("ADDRESS")
if listenAddress == "" {
listenAddress = "0.0.0.0:9000"
}

log.Printf("listening on: %s", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
log.Fatal("error on ListenAndServe: %s", err)
}
}
20 changes: 3 additions & 17 deletions server/main.go → server/server.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package main
package server

import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"path"
Expand All @@ -18,7 +17,6 @@ const (
)

var (
listenAddress string
publicDir string
indexTemplate *template.Template
)
Expand All @@ -30,26 +28,19 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
}
}

func main() {
func init() {
publicDir = os.Getenv("PUBLIC_DIR")
if publicDir == "" {
publicDir = "./frontend/public"
}

listenAddress = os.Getenv("ADDRESS")
if listenAddress == "" {
listenAddress = "0.0.0.0:9000"
}

if _, err := os.Stat(path.Join(publicDir, "index.html")); err != nil {
fmt.Println("Static files do not exist in provided PUBLIC_DIR env variable.")
os.Exit(1)
}

handle()
}

func handle() {
func Handle() {
r := mux.NewRouter()

// Simple static file server for requests containing static prefix.
Expand All @@ -63,9 +54,4 @@ func handle() {
r.HandleFunc("/{path:.*}", IndexHandler)

http.Handle("/", r)

log.Printf("listening on: %s", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
log.Fatal("error on ListenAndServe: %s", err)
}
}

0 comments on commit 21c371e

Please sign in to comment.