Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: KSP-SpaceDock/SpaceDock-Backend
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b92150ec43ed
Choose a base ref
...
head repository: KSP-SpaceDock/SpaceDock-Backend
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e2227c8aefb8
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 19, 2017

  1. Config overhaul

    Dorian Stoll committed Mar 19, 2017
    Copy the full SHA
    f1ef636 View commit details
  2. general.go (storage downloads)

    Dorian Stoll committed Mar 19, 2017
    Copy the full SHA
    e2227c8 View commit details
Showing with 136 additions and 94 deletions.
  1. +56 −0 config/config.example.yml
  2. +0 −29 config/config.yml.example
  3. +0 −1 src/SpaceDock/app.go
  4. +52 −0 src/SpaceDock/routes/general.go
  5. +1 −0 src/SpaceDock/routes/init.go
  6. +27 −64 src/SpaceDock/settings.go
56 changes: 56 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# debug: false for deployed instances
debug: true

# The displayed name of this site
site-name: ""
# The email where users who need help write to
support-mail: ""

# Change this to the actual location of your site
protocol: "http"
domain: "localhost:5000"

# Enable offloading of downloads to the reverse proxy server. Make sure the reverse proxy is set up!
# valid values are:
# false - disable offloading
# nginx - enable X-Accel headers
# apache - enable X-Sendfile headers
use-x-accel: "false"

# Set this to False to disable registration
registration: true

# This lets you choose what to bind to
host: "0.0.0.0"
port: 5000

# To send emails, fill out these details
smtp-host: ""
smtp-port: 0
smtp-user: ""
smtp-password: ""
smtp-tls: false

# SQL settings
dialect: "mysql"
connection-data: ""

# Absolute path to the directory you want to store mods in
storage: ""

# Domain for a storage CDN
cdn-domain: ""

# Thumbnail size in WxH format, leave blank to disable screenshots
thumbnail-size: ""

# Access limiting
# <number of requests>-<span>
# Valid values for span are:
# S - second
# M - minute
# H - hour
request-limit: "10-S"

# Disables the same origin policy on the client
disable-same-origin: false
29 changes: 0 additions & 29 deletions config/config.yml.example

This file was deleted.

1 change: 0 additions & 1 deletion src/SpaceDock/app.go
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ var App *iris.Framework
func init() {
log.SetOutput(os.Stdout)
log.Print("SpaceDock-Backend -- Version: {$VERSION}")
log.Print("* Loading configuration")
LoadSettings()

// Connect to the database
52 changes: 52 additions & 0 deletions src/SpaceDock/routes/general.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
SpaceDock Backend
API Backend for the SpaceDock infrastructure to host modfiles for various games
SpaceDock Backend is licensed under the Terms of the MIT License.
Copyright (c) 2017 Dorian Stoll (StollD), RockyTV
*/

package routes

import (
"SpaceDock"
"gopkg.in/kataras/iris.v6"
"mime"
"path/filepath"
)

/*
Registers the routes for the general routes
*/
func GeneralRegister() {
Register(GET, "/content/*path", download)
}

/*
Path: /content/*path
Method: GET
Description: Downloads a file from the storage.
*/
func download(ctx *iris.Context) {
// Get the path
path := ctx.GetString("path")

// Check for a CDN
if SpaceDock.Settings.CdnDomain != "" {
ctx.Redirect("http://" + SpaceDock.Settings.CdnDomain + "/" + path, iris.StatusMovedPermanently)
return
}

// Check for X-Sendfile
if SpaceDock.Settings.UseXAccel == "nginx" {
ctx.SetHeader("Content-Type", mime.TypeByExtension(filepath.Ext(filepath.Join(SpaceDock.Settings.Storage, path))))
ctx.SetHeader("Content-Disposition", "attachment; filename=" + filepath.Base(path))
ctx.SetHeader("X-Accel-Redirect", "/internal/" + path)
} else if SpaceDock.Settings.UseXAccel == "apache" {
ctx.SetHeader("Content-Type", mime.TypeByExtension(filepath.Ext(filepath.Join(SpaceDock.Settings.Storage, path))))
ctx.SetHeader("Content-Disposition", "attachment; filename=" + filepath.Base(path))
ctx.SetHeader("X-Sendfile", filepath.Join(SpaceDock.Settings.Storage, path))
} else {
ctx.SendFile(filepath.Join(SpaceDock.Settings.Storage, path), filepath.Base(path))
}
}
1 change: 1 addition & 0 deletions src/SpaceDock/routes/init.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ func init() {
AccountsRegister()
AdminRegister()
GameRegister()
GeneralRegister()
PublisherRegister()
TokensRegister()
UserRegister()
91 changes: 27 additions & 64 deletions src/SpaceDock/settings.go
Original file line number Diff line number Diff line change
@@ -9,25 +9,23 @@
package SpaceDock

import (
"flag"
"github.com/jinzhu/configor"
"log"
"os"
)

/*
All the config variables from either the commandline, or
a dedicated config file
All the config variables from the config file
*/
type SettingsData struct {
// Whether the app should run in debug mode
Debug bool

// The displayed name of this site
SiteName string
SiteName string `yaml:"site-name" json:"site-name"`

// The email where users who need help write to
SupportMail string
SupportMail string `yaml:"support-mail" json:"support-mail"`

// The actual location of your site
Protocol string
@@ -41,36 +39,39 @@ type SettingsData struct {
Port int

// Details for sending emails
SmtpHost string
SmtpPort int
SmtpUser string
SmtpPassword string
SmtpTls bool
SmtpHost string `yaml:"smtp-host" json:"smtp-host"`
SmtpPort int `yaml:"smtp-port" json:"smtp-port"`
SmtpUser string `yaml:"smtp-user" json:"smtp-user"`
SmtpPassword string `yaml:"smtp-password" json:"smtp-password"`
SmtpTls bool `yaml:"smtp-tls" json:"smtp-tls"`

// Database connection
Dialect string
ConnectionData string
Dialect string
ConnectionData string `yaml:"connection-data" json:"connection-data"`

// The directory where files are stored
Storage string

// Domain for a storage CDN
CdnDomain string
CdnDomain string `yaml:"cdn-domain" json:"cdn-domain"`

// Thumbnail size in WxH format
ThumbnailSize string
ThumbnailSize string `yaml:"thumbnail-size" json:"thumbnail-size"`

// Mod URL expression, used for sending emails containing links to the frontend
// ModUrl string

// Whether CORS should be enabled
DisableSameOrigin bool
DisableSameOrigin bool `yaml:"disable-same-origin" json:"disable-same-origin"`

// Whether the code should generate a dummy database
CreateDefaultDatabase bool
CreateDefaultDatabase bool `yaml:"create-default-database" json:"create-default-database"`

// How many requests can be made in a defined time span
RequestLimit string
RequestLimit string `yaml:"request-limit" json:"request-limit"`

// Support for X-Accel
UseXAccel string `yaml:"use-x-accel" json:"use-x-accel"`
}

/*
@@ -79,58 +80,20 @@ type SettingsData struct {
var Settings SettingsData

/*
The path of the configuration file (if it exists)
*/
var configFile string

/*
Loads the settings from commandline and from a config file
Loads the settings from the config file
*/
func LoadSettings() {
loadFromCommandLine()
loadFromConfigFile()
}

/*
Loads the settings from commandline parameters
*/
func loadFromCommandLine() {
flag.BoolVar(&Settings.Debug, "debug", false, "Whether the app should run in debug mode")
flag.StringVar(&Settings.SiteName, "sitename", "", "The displayed name of this site")
flag.StringVar(&Settings.SupportMail, "support-mail", "", "The email where users who need help write to")
flag.StringVar(&Settings.Protocol, "protocol", "http", "The protocol your site is using (http/https)")
flag.StringVar(&Settings.Domain, "domain", "localhost:5000", "The actual location of your site")
flag.BoolVar(&Settings.Registration, "registration", true, "Whether registering new users on the site is allowed")
flag.StringVar(&Settings.Host, "host", "0.0.0.0", "The IP Address to bind to")
flag.IntVar(&Settings.Port, "port", 5000, "The port to bind to")
flag.StringVar(&Settings.SmtpHost, "smtphost", "", "The hostname of your SMTP server (leave empty if you dont want to send emails)")
flag.IntVar(&Settings.SmtpPort, "smtpport", 0, "The port your SMTP Server listens on")
flag.StringVar(&Settings.SmtpUser, "smtpuser", "", "The username that should get used to log into your SMTP server")
flag.StringVar(&Settings.SmtpPassword, "smtppassword", "", "The password of your SMTP User")
flag.BoolVar(&Settings.SmtpTls, "smtptls", false, "Whether TLS should be used (STARTTLS)")
flag.StringVar(&Settings.Dialect, "dialect", "", "The SQL dialect used by your database")
flag.StringVar(&Settings.ConnectionData, "connectiondata", "", "Describes the connection to your SQL Database")
flag.StringVar(&Settings.Storage, "storage", "", "The directory where all modfiles should get stored")
flag.StringVar(&Settings.CdnDomain, "cdndomain", "", "Whether a custom CDN should be used instead of the local storage")
flag.StringVar(&Settings.ThumbnailSize, "thumbnailsize", "", "Thumbnail size in WxH format")
flag.BoolVar(&Settings.DisableSameOrigin, "disablesameorigin", false, "Enables CORS (Cross Origin Requests)")
flag.BoolVar(&Settings.CreateDefaultDatabase, "createdefaultdatabase", false, "")
flag.StringVar(&Settings.RequestLimit, "requestlimit", "1-S", "How many requests can be made in a defined time span")

flag.StringVar(&configFile, "configfile", "", "The path for a dedicated configuration file")
flag.Parse()
LoadFromConfigFile(&Settings, "config.yml")
}

/*
Loads the settings from a dedicated configuration file
Loads the settings from a configuration file
*/
func loadFromConfigFile() {
if configFile != "" {
log.Printf("* Found configuration file: %s", configFile)
os.Setenv("CONFIGOR_ENV_PREFIX", "SPACEDOCK")
err := configor.Load(&Settings, configFile)
if err != nil {
log.Fatalf("* Failed to parse configuration file: %s", err)
}
func LoadFromConfigFile(data interface{}, configFile string) {
log.Printf("* Loading configuration file: config/%s", configFile)
os.Setenv("CONFIGOR_ENV_PREFIX", "SPACEDOCK")
err := configor.Load(data, "config/" + configFile)
if err != nil {
log.Fatalf("* Failed to parse configuration file: %s", err)
}
}