Skip to content

Commit

Permalink
Fixes for config and static files
Browse files Browse the repository at this point in the history
  • Loading branch information
ldb committed Jun 5, 2018
1 parent 2ae3af4 commit 665b0d8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func main() {
cS := service.NewCourseService(repository.CourseRepository)

server := http.AppServer{
Host: c.Host,
Static: c.StaticDir,
UserService: uS,
CourseService: cS,
}
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import "os"

type config struct {
Port,
Host,
MongoHost,
MongoPort,
MongoDB,
Expand All @@ -13,9 +13,9 @@ type config struct {
}

func GetConfig() config {
port, ok := os.LookupEnv("PORT")
host, ok := os.LookupEnv("HOST")
if !ok {
port = "8080"
host = ":8080"
}

mongoHost, ok := os.LookupEnv("MONGO_HOST")
Expand Down Expand Up @@ -49,7 +49,7 @@ func GetConfig() config {
}

return config{
Port: port,
Host: host,
MongoHost: mongoHost,
MongoPort: mongoPort,
MongoDB: mongoDB,
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestGetConfig(t *testing.T) {
key string
value string
}{
{"PORT", "test"},
{"HOST", "test"},
{"MONGO_HOST", "testurl"},
{"MONGO_PORT", "testport"},
{"MONGO_DB", "testdb"},
Expand All @@ -36,7 +36,7 @@ func TestGetConfig(t *testing.T) {
"testdir"}},
{"unset", true,
config{
"8080",
":8080",
"localhost",
"27017",
"eduboard",
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
environment:
MONGO_HOST: "mongo"
MONGO_PORT: "27017"
STATIC_DIR: "/var/www/static/"
links:
- mongo:mongo
volumes:
- ./static:/var/www/static
6 changes: 4 additions & 2 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

type AppServer struct {
Host string
Static string
UserService eduboard.UserService
CourseService eduboard.CourseService
httpServer *http.Server
Expand All @@ -20,10 +22,10 @@ func (a *AppServer) initialize() {
mux := http.NewServeMux()
mux.Handle("/api/v1/", NewAuthMiddleware(a.UserService, protected))
mux.Handle("/api/", public)
mux.Handle("/", http.FileServer(http.Dir("./static")))
mux.Handle("/", http.FileServer(http.Dir(a.Static)))

a.httpServer = &http.Server{
Addr: ":8080",
Addr: a.Host,
ReadTimeout: 1 * time.Second,
WriteTimeout: 1 * time.Second,
MaxHeaderBytes: 1 << 20,
Expand Down

0 comments on commit 665b0d8

Please sign in to comment.