Files
fnx_web/init/init.go

66 lines
1.7 KiB
Go
Raw Normal View History

2017-11-10 12:39:55 +01:00
package init
import (
"os"
2021-11-16 15:20:15 +01:00
"fornaxian.tech/config"
"fornaxian.tech/log"
2020-07-29 17:27:36 +02:00
"fornaxian.tech/pixeldrain_web/webcontroller"
2017-11-10 12:39:55 +01:00
"github.com/julienschmidt/httprouter"
)
2019-12-30 13:00:00 +01:00
// DefaultConfig is the default configuration for Pixeldrain Web
2021-03-04 17:10:59 +01:00
const DefaultConfig = `## Pixeldrain Web UI server configuration
# Address used in the browser for making requests directly to the API. Can be
# relative to the current domain name
api_url_external = "/api"
# Address used to make internal API requests to the backend
api_url_internal = "https://pixeldrain.com/api"
2019-12-30 13:00:00 +01:00
2022-11-07 18:10:06 +01:00
# When connecting to the API over a Unix domain socket you should enter the
# socket path here. api_url_internal needs to be correct too, as the API path
# prefix will be derived from there
api_socket_path = ""
2021-01-12 23:20:32 +01:00
website_address = "https://pixeldrain.com"
2021-03-04 17:10:59 +01:00
session_cookie_domain = ""
2019-12-30 13:00:00 +01:00
resource_dir = "res"
2021-03-04 17:10:59 +01:00
# Parse all the templates every time a request comes in
debug_mode = true
# Create proxy listeners to forward all requests made to /api to
# api_url_internal
proxy_api_requests = true
# When this is true every request will return a maintainance HTML page
2019-12-30 13:00:00 +01:00
maintenance_mode = false
`
2017-11-10 12:39:55 +01:00
// Init initializes the Pixeldrain Web UI controllers
2018-08-15 10:11:31 +02:00
func Init(r *httprouter.Router, prefix string, setLogLevel bool) {
2021-03-11 18:52:55 +01:00
log.Colours = true
2017-11-10 12:39:55 +01:00
log.Info("Starting web UI server (PID %v)", os.Getpid())
2022-11-07 18:10:06 +01:00
var conf webcontroller.Config
var _, err = config.New(
2019-12-30 13:00:00 +01:00
DefaultConfig,
"",
"pdwebconf.toml",
2022-11-07 18:10:06 +01:00
&conf,
true,
)
if err != nil {
log.Error("Failed to load config file: %s", err)
os.Exit(1)
}
2017-11-10 12:39:55 +01:00
2022-11-07 18:10:06 +01:00
if !conf.DebugMode && setLogLevel {
2018-08-15 10:04:43 +02:00
log.SetLogLevel(log.LevelInfo)
}
2022-11-07 18:10:06 +01:00
webcontroller.New(r, prefix, conf)
2017-11-10 12:39:55 +01:00
}