Add ability to serve static files.
Added a configuration key, `service.staticpath`, to allow the serving of files from the provided path. By default, the path is empty and Vikunja's existing behaviour is unchanged. Providing a path via the configuration, adds a static file middleware to serve the path's contents from root (/). Being able to serve static files allows the api service to also serve the frontend content. This adds 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. Future improvements could embed a copy of the frontend files via the fs.FS and embed package. Alternatively a reverse proxy could be offered using http/httputil's ReverseProxy; this would allow another server to maintain a default set of frontend files without embedding.
This commit is contained in:
parent
7b10176a10
commit
d998b8099f
|
@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|||
|
||||
All releases can be found on https://code.vikunja.io/api/releases.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
* Add static file support for simplified deployment
|
||||
|
||||
## [0.18.1] - 2021-09-08
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue