Skip to content

Commit 1f3f7dd

Browse files
authored
server: add read only mode (#92)
In read only mode the endpoint to save new effects or add new versions is deactivated. Also in the gallery the create button is deactivated and there is a notice that says: The server is in maintenance mode. You can not create or modify effects. The button to save effects in the editor is not deactivated as it will take a bit more time and wanted to have the page up as soon as possible.
1 parent b0a0012 commit 1f3f7dd

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

server/assets/gallery.html

+6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ <h1><a href="/" style="text-transform:uppercase">GLSL Sandbox</a> <a href="https
123123
<a href="https://twitter.com/mrdoob">@mrdoob</a><br/>
124124
editor by <a href="https://twitter.com/mrdoob">@mrdoob</a>, <a href="https://twitter.com/mrkishi">@mrkishi</a>, <a href="https://twitter.com/p01">@p01</a>, <a href="https://twitter.com/alteredq">@alteredq</a>, <a href="https://twitter.com/kusmabite">@kusmabite</a> and <a href="https://twitter.com/emackey">@emackey</a>
125125
<br/><br/>
126+
127+
{{ if .ReadOnly }}
128+
<h2 style="color:#ff6961">The server is in maintenance mode. You can not create or modify effects.</h2>
129+
{{ else }}
126130
<a href="/e"><button>new shader</button></a>
131+
{{ end }}
132+
127133
<div id="gallery">
128134

129135
{{ if .Admin }}

server/cmd/glslsandbox/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Config struct {
2525
TLSAddr string `envconfig:"TLS_ADDR"`
2626
Domains string `envconfig:"DOMAINS" default:"www.glslsandbox.com,glslsandbox.com"`
2727
Dev bool `envconfig:"DEV" default:"true"`
28+
ReadOnly bool `envconfig:"READ_ONLY" default:"false"`
2829
}
2930

3031
func main() {
@@ -82,6 +83,7 @@ func start() error {
8283
auth,
8384
cfg.DataPath,
8485
cfg.Dev,
86+
cfg.ReadOnly,
8587
)
8688
if err != nil {
8789
return fmt.Errorf("could not create server: %w", err)

server/server.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ const (
2727
perPage = 50
2828
)
2929

30-
var (
31-
ErrInvalidData = fmt.Errorf("invalid data")
32-
)
30+
var ErrInvalidData = fmt.Errorf("invalid data")
3331

3432
type Template struct {
3533
templates *template.Template
@@ -80,6 +78,7 @@ type Server struct {
8078
effects *store.Effects
8179
auth *Auth
8280
dataPath string
81+
readOnly bool
8382
}
8483

8584
func New(
@@ -90,6 +89,7 @@ func New(
9089
auth *Auth,
9190
dataPath string,
9291
dev bool,
92+
readOnly bool,
9393
) (*Server, error) {
9494
var tpl *template.Template
9595
if !dev {
@@ -115,6 +115,7 @@ func New(
115115
effects: e,
116116
auth: auth,
117117
dataPath: dataPath,
118+
readOnly: readOnly,
118119
}, nil
119120
}
120121

@@ -163,7 +164,10 @@ func (s *Server) routes() {
163164
s.echo.GET("/", s.indexHandler)
164165
s.echo.GET("/e", s.effectHandler)
165166
s.echo.GET("/e_", s.effectHandler_)
166-
s.echo.POST("/e", s.saveHandler)
167+
168+
if !s.readOnly {
169+
s.echo.POST("/e", s.saveHandler)
170+
}
167171

168172
cors := middleware.CORSWithConfig(middleware.CORSConfig{
169173
Skipper: middleware.DefaultSkipper,
@@ -228,6 +232,8 @@ type galleryData struct {
228232
NextPage string
229233
// Admin is true when accessing "/admin" path.
230234
Admin bool
235+
// ReadOnly tells the server is in read only mode.
236+
ReadOnly bool
231237
}
232238

233239
func (s *Server) indexRender(c echo.Context, admin bool) error {
@@ -290,6 +296,7 @@ func (s *Server) indexRender(c echo.Context, admin bool) error {
290296
IsPrevious: page > 0,
291297
PreviousPage: previousPage,
292298
Admin: admin,
299+
ReadOnly: s.readOnly,
293300
}
294301

295302
return c.Render(http.StatusOK, "gallery", d)

0 commit comments

Comments
 (0)