Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ omnibus/pkg
tmp
!test/fixtures/spec/*.gem
dist/
bin/
bin/
.vercel
.env*
4 changes: 4 additions & 0 deletions cmd/gemfast-server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
var rootCmd = &cobra.Command{
Use: "gemfast-server",
Short: "Gemfast is a rubygems server written in Go",
// When invoked with no subcommand, default to running the server (same as "start").
Run: func(cmd *cobra.Command, args []string) {
start()
},
}

func Execute() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/gemfast-server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var configPath string

func init() {
startCmd.Flags().StringVarP(&configPath, "config", "c", "", "Path to the config file")
// Expose the same flag on the root command so it works when invoking
// gemfast-server with no subcommand (defaults to start).
rootCmd.Flags().StringVarP(&configPath, "config", "c", "", "Path to the config file")
rootCmd.AddCommand(startCmd)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -46,6 +47,11 @@ func (api *API) Run() {
api.loadMiddleware()
api.registerRoutes()
port := fmt.Sprintf(":%d", api.cfg.Port)
// Honor the PORT env var (e.g. injected by Vercel) when set, falling back
// to the configured/default port otherwise.
if p := os.Getenv("PORT"); p != "" {
port = ":" + p
}
if api.cfg.Mirrors[0].Enabled {
log.Info().Str("detail", api.cfg.Mirrors[0].Upstream).Msg("mirroring upstream gem server")
}
Expand Down
15 changes: 4 additions & 11 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"

"github.com/gemfast/server/internal/utils"
"github.com/hashicorp/hcl/v2/hclsimple"
Expand Down Expand Up @@ -125,16 +124,10 @@ func (c *Config) setDefaultServerConfig() {
}
configureLogLevel(c.LogLevel)
if c.Dir == "" {
if c.user.Username == "root" {
c.Dir = "/var/lib/gemfast/data"
} else if runtime.GOOS == "darwin" {
c.Dir = fmt.Sprintf("%s/Library/Application Support/gemfast", c.user.HomeDir)
} else if runtime.GOOS == "linux" {
c.Dir = fmt.Sprintf("%s/gemfast", os.Getenv("XDG_DATA_HOME"))
if c.Dir == "/gemfast" {
c.Dir = fmt.Sprintf("%s/.local/share/gemfast", c.user.HomeDir)
}
}
// NOTE: hardcoded to /tmp for the Vercel test deployment, where /tmp
// is the only writable location. This is intentionally not
// platform-specific for now.
c.Dir = "/tmp/gemfast"
}
if c.GemDir == "" {
c.GemDir = fmt.Sprintf("%s/gems", c.Dir)
Expand Down
Loading