summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/cliactions/server/server.go3
-rw-r--r--internal/config/config.go9
-rw-r--r--internal/config/default.go7
-rw-r--r--internal/config/template.go2
-rw-r--r--internal/web/base.go85
5 files changed, 104 insertions, 2 deletions
diff --git a/internal/cliactions/server/server.go b/internal/cliactions/server/server.go
index 74b1c789a..c27ec7fac 100644
--- a/internal/cliactions/server/server.go
+++ b/internal/cliactions/server/server.go
@@ -44,6 +44,7 @@ import (
timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/timeline"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
+ "github.com/superseriousbusiness/gotosocial/internal/web"
)
var models []interface{} = []interface{}{
@@ -123,6 +124,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
appsModule := app.New(c, processor, log)
followRequestsModule := followrequest.New(c, processor, log)
webfingerModule := webfinger.New(c, processor, log)
+ webBaseModule := web.New(c, processor, log)
usersModule := user.New(c, processor, log)
timelineModule := timeline.New(c, processor, log)
notificationModule := notification.New(c, processor, log)
@@ -143,6 +145,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
authModule,
// now everything else
+ webBaseModule,
accountModule,
instanceModule,
appsModule,
diff --git a/internal/config/config.go b/internal/config/config.go
index 8a5e27a0c..b0263b170 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -170,6 +170,11 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) error {
c.TemplateConfig.BaseDir = f.String(fn.TemplateBaseDir)
}
+ // template flags
+ if c.TemplateConfig.AssetBaseDir == "" || f.IsSet(fn.AssetBaseDir) {
+ c.TemplateConfig.AssetBaseDir = f.String(fn.AssetBaseDir)
+ }
+
// accounts flags
if f.IsSet(fn.AccountsOpenRegistration) {
c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration)
@@ -283,6 +288,7 @@ type Flags struct {
DbDatabase string
TemplateBaseDir string
+ AssetBaseDir string
AccountsOpenRegistration string
AccountsApprovalRequired string
@@ -326,6 +332,7 @@ type Defaults struct {
DbDatabase string
TemplateBaseDir string
+ AssetBaseDir string
AccountsOpenRegistration bool
AccountsRequireApproval bool
@@ -371,6 +378,7 @@ func GetFlagNames() Flags {
DbDatabase: "db-database",
TemplateBaseDir: "template-basedir",
+ AssetBaseDir: "asset-basedir",
AccountsOpenRegistration: "accounts-open-registration",
AccountsApprovalRequired: "accounts-approval-required",
@@ -417,6 +425,7 @@ func GetEnvNames() Flags {
DbDatabase: "GTS_DB_DATABASE",
TemplateBaseDir: "GTS_TEMPLATE_BASEDIR",
+ AssetBaseDir: "GTS_ASSET_BASEDIR",
AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION",
AccountsApprovalRequired: "GTS_ACCOUNTS_APPROVAL_REQUIRED",
diff --git a/internal/config/default.go b/internal/config/default.go
index f63579753..8a53f239e 100644
--- a/internal/config/default.go
+++ b/internal/config/default.go
@@ -18,7 +18,8 @@ func TestDefault() *Config {
ApplicationName: defaults.ApplicationName,
},
TemplateConfig: &TemplateConfig{
- BaseDir: defaults.TemplateBaseDir,
+ BaseDir: defaults.TemplateBaseDir,
+ AssetBaseDir: defaults.AssetBaseDir,
},
AccountsConfig: &AccountsConfig{
OpenRegistration: defaults.AccountsOpenRegistration,
@@ -71,7 +72,8 @@ func Default() *Config {
ApplicationName: defaults.ApplicationName,
},
TemplateConfig: &TemplateConfig{
- BaseDir: defaults.TemplateBaseDir,
+ BaseDir: defaults.TemplateBaseDir,
+ AssetBaseDir: defaults.AssetBaseDir,
},
AccountsConfig: &AccountsConfig{
OpenRegistration: defaults.AccountsOpenRegistration,
@@ -124,6 +126,7 @@ func GetDefaults() Defaults {
DbDatabase: "postgres",
TemplateBaseDir: "./web/template/",
+ AssetBaseDir: "./web/assets/",
AccountsOpenRegistration: true,
AccountsRequireApproval: true,
diff --git a/internal/config/template.go b/internal/config/template.go
index eba86f8e6..9c524471c 100644
--- a/internal/config/template.go
+++ b/internal/config/template.go
@@ -22,4 +22,6 @@ package config
type TemplateConfig struct {
// Directory from which gotosocial will attempt to load html templates (.tmpl files).
BaseDir string `yaml:"baseDir"`
+ // Directory from which static files are served
+ AssetBaseDir string `yaml:"assetDir"`
}
diff --git a/internal/web/base.go b/internal/web/base.go
new file mode 100644
index 000000000..e54150ebc
--- /dev/null
+++ b/internal/web/base.go
@@ -0,0 +1,85 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package web
+
+import (
+ "fmt"
+ "net/http"
+ "os"
+ "path/filepath"
+
+ "github.com/gin-contrib/static"
+ "github.com/gin-gonic/gin"
+ "github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/api"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/processing"
+ "github.com/superseriousbusiness/gotosocial/internal/router"
+)
+
+type Module struct {
+ config *config.Config
+ processor processing.Processor
+ log *logrus.Logger
+}
+
+func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
+ return &Module{
+ config: config,
+ log: log,
+ processor: processor,
+ }
+}
+
+func (m *Module) baseHandler(c *gin.Context) {
+ l := m.log.WithField("func", "BaseGETHandler")
+ l.Trace("serving index html")
+
+ instance, err := m.processor.InstanceGet(m.config.Host)
+ if err != nil {
+ l.Debugf("error getting instance from processor: %s", err)
+ c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
+ return
+ }
+
+ // FIXME: fill in more variables?
+ c.HTML(http.StatusOK, "index.tmpl", gin.H{
+ "instance": instance,
+ "countUsers": 3,
+ "countStatuses": 42069,
+ "version": "1.0.0",
+ "adminUsername": "@admin",
+ })
+}
+
+// Route satisfies the RESTAPIModule interface
+func (m *Module) Route(s router.Router) error {
+
+ // serve static files from /assets
+ cwd, err := os.Getwd()
+ if err != nil {
+ return fmt.Errorf("error getting current working directory: %s", err)
+ }
+ assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir)
+ s.AttachMiddleware(static.Serve("/assets", static.LocalFile(assetPath, false)))
+
+ // serve front-page
+ s.AttachHandler(http.MethodGet, "/", m.baseHandler)
+ return nil
+}