feat: ability to serve static files (#1174)
Added the configuration key, `service.staticpath`, to serve files from the configuration path on root (/). Serving static files allows the api service to also serve the frontend content. This is a simple option for deploying Vikunja without needing any other servers or proxies. Running a complete instance becomes: VIKUNJA_SERVICE_STATICPATH=/path/to/frontend ./vikunja Where `/path/to/frontend` is a copy of Vikunja's frontend static files. ## Implementation Providing a path, via the configuration or environment, adds a static file middleware to serve the path's contents from root (/). By default, the configuration path is empty and Vikunja's existing behaviour is unchanged. Co-authored-by: Graham Miln <graham.miln@dssw.co.uk> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/1174 Reviewed-by: konrad <k@knt.li> Co-authored-by: grahammiln <grahammiln@noreply.kolaente.de> Co-committed-by: grahammiln <grahammiln@noreply.kolaente.de>
This commit is contained in:
@ -47,6 +47,7 @@ const (
|
||||
ServiceFrontendurl Key = `service.frontendurl`
|
||||
ServiceEnableCaldav Key = `service.enablecaldav`
|
||||
ServiceRootpath Key = `service.rootpath`
|
||||
ServiceStaticpath Key = `service.staticpath`
|
||||
ServiceMaxItemsPerPage Key = `service.maxitemsperpage`
|
||||
// Deprecated: Use metrics.enabled
|
||||
ServiceEnableMetrics Key = `service.enablemetrics`
|
||||
@ -274,6 +275,7 @@ func InitDefaultConfig() {
|
||||
ServiceEnableCaldav.setDefault(true)
|
||||
|
||||
ServiceRootpath.setDefault(getBinaryDirLocation())
|
||||
ServiceStaticpath.setDefault("")
|
||||
ServiceMaxItemsPerPage.setDefault(50)
|
||||
ServiceEnableMetrics.setDefault(false)
|
||||
ServiceMotd.setDefault("")
|
||||
|
@ -203,6 +203,11 @@ func RegisterRoutes(e *echo.Echo) {
|
||||
// healthcheck
|
||||
e.GET("/health", HealthcheckHandler)
|
||||
|
||||
// static files
|
||||
if static := config.ServiceStaticpath.GetString(); static != "" {
|
||||
e.Use(middleware.Static(static))
|
||||
}
|
||||
|
||||
// CORS_SHIT
|
||||
if config.CorsEnable.GetBool() {
|
||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
|
Reference in New Issue
Block a user