Skip to content

Commit 35fb3eb

Browse files
committed
chore: add nix flake for dev, fix: remove frontend envs
1 parent 567832a commit 35fb3eb

File tree

16 files changed

+139
-65
lines changed

16 files changed

+139
-65
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@ dist
139139
.yarn/build-state.yml
140140
.yarn/install-state.gz
141141
.pnp.*
142+
143+
.envrc
144+
.direnv

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ARG PUBLIC_API_URL="https://status.pluralkit.me"
2-
31
FROM alpine:latest AS build
42

53
RUN apk add nodejs npm go git make
@@ -10,8 +8,6 @@ COPY Makefile /build/
108
COPY .git/ /build/.git
119

1210
WORKDIR /build
13-
ARG PUBLIC_API_URL
14-
ENV PUBLIC_API_URL=$PUBLIC_API_URL
1511
RUN make
1612

1713
FROM caddy:2.10 AS caddy

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ clean:
1818
dev: backend
1919
export $(xargs < .env)
2020
rm -rf build/srv/* && mkdir -p build build/srv
21-
cd frontend && npm install && PUBLIC_API_URL="http://localhost:8080" npm run build && mv -f build/* ../build/srv
21+
cd frontend && npm install && npm run build && mv -f build/* ../build/srv
2222
cd build && pluralkit__status__run_dev=true ./status

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@ type Config struct {
4545

4646
### Frontend:
4747
```
48-
PUBLIC_API_URL="http://status.pluralkit.me"
49-
PUBLIC_SHARD_URL="https://api.pluralkit.me/private/discord/shard_state"
5048
```

backend/api/routes.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ import (
1111
)
1212

1313
type API struct {
14-
Config util.Config
15-
Logger *slog.Logger
16-
Database *db.DB
14+
Config util.Config
15+
Logger *slog.Logger
16+
Database *db.DB
17+
httpClient http.Client
1718
}
1819

1920
func NewAPI(config util.Config, logger *slog.Logger, database *db.DB) *API {
2021
moduleLogger := logger.With(slog.String("module", "API"))
2122
return &API{
22-
Config: config,
23-
Logger: moduleLogger,
24-
Database: database,
23+
Config: config,
24+
Logger: moduleLogger,
25+
Database: database,
26+
httpClient: http.Client{},
2527
}
2628
}
2729

@@ -54,6 +56,7 @@ func (a *API) SetupRoutes(router *chi.Mux) {
5456
router.Route("/api/v1", func(r chi.Router) {
5557

5658
r.Get("/status", a.GetStatus)
59+
r.Get("/shards", a.GetShardStatus)
5760

5861
r.Route("/incidents", func(r chi.Router) {
5962
r.Get("/", a.GetIncidents)

backend/api/status.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"io"
45
"log/slog"
56
"net/http"
67
"pluralkit/status/util"
@@ -33,3 +34,30 @@ func (a *API) GetStatus(w http.ResponseWriter, r *http.Request) {
3334
return
3435
}
3536
}
37+
38+
func (a *API) GetShardStatus(w http.ResponseWriter, r *http.Request) {
39+
req, err := http.NewRequest(http.MethodGet, a.Config.ShardsEndpoint, nil)
40+
if err != nil {
41+
http.Error(w, "error while creating request", 500)
42+
a.Logger.Error("error while creating request", slog.Any("error", err))
43+
return
44+
}
45+
resp, err := a.httpClient.Do(req)
46+
if err != nil {
47+
http.Error(w, "error while getting shard status", 500)
48+
a.Logger.Error("error while getting shard status", slog.Any("error", err))
49+
return
50+
} else if resp.StatusCode != 200 {
51+
http.Error(w, "error while getting shard status", 500)
52+
a.Logger.Error("non 200 when getting shard status")
53+
return
54+
}
55+
defer resp.Body.Close()
56+
57+
_, err = io.Copy(w, resp.Body)
58+
if err != nil {
59+
http.Error(w, "error while copying response", 500)
60+
a.Logger.Error("error while copying response", slog.Any("error", err))
61+
return
62+
}
63+
}

backend/util/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (l *SlogLevel) UnmarshalText(text []byte) error {
2828

2929
type Config struct {
3030
BindAddr string `env:"pluralkit__status__addr" envDefault:"0.0.0.0:8080"`
31+
ShardsEndpoint string `env:"pluralkit__status__shards_endpoint" envDefault:"https://api.pluralkit.me/private/discord/shard_state"`
3132
AuthToken string `env:"pluralkit__status__auth_token"`
3233
NotificationWebhook string `env:"pluralkit__status__notification_webhook"`
3334
NotificationRole string `env:"pluralkit__status__notification_role"`

backend/webhook/discord.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (dw *DiscordWebhook) genIncidentMessage(incident util.Incident) Message {
105105
},
106106
{
107107
Type: int(TextDisplay),
108-
Content: fmt.Sprintf("# %s\n-# **status:** *%s*\t**impact:** *%s*", incident.Name, incident.Status, incident.Impact),
108+
Content: fmt.Sprintf("## %s\n-# **status:** *%s*\t**impact:** *%s*", incident.Name, incident.Status, incident.Impact),
109109
},
110110
{
111111
Type: int(Seperator),
@@ -140,9 +140,9 @@ func (dw *DiscordWebhook) genUpdateMessage(incident util.Incident, update util.I
140140
Roles: []string{dw.notifRole},
141141
}
142142
}
143-
nameText := fmt.Sprintf("# update: %s", incident.Name)
143+
nameText := fmt.Sprintf("## update: %s", incident.Name)
144144
if update.Status != nil {
145-
nameText = fmt.Sprintf("# update: %s\n-# **status:** *%s*", incident.Name, incident.Status)
145+
nameText = fmt.Sprintf("## update: %s\n-# **status:** *%s*", incident.Name, incident.Status)
146146
}
147147
color := 0
148148
switch incident.Impact {

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ services:
33
build:
44
context: .
55
target: backend
6-
args:
7-
- PUBLIC_API_URL=""
86
volumes:
97
- "data:/app/data"
108
environment:

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)