Skip to content

Commit 92c9873

Browse files
committed
add a way to check that a cron task is triggered by smallweb
1 parent dbf63e3 commit 92c9873

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

internal/cmd/up.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func NewCmdUp() *cobra.Command {
214214

215215
// simulate a get request to the cron job path
216216
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s%s", wk.App.Domain, path), nil)
217+
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", wk.Secret))
217218
if err != nil {
218219
return fmt.Errorf("failed to create request: %w", err)
219220
}

internal/worker/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package worker
33
import (
44
"bufio"
55
"context"
6+
"crypto/rand"
67
_ "embed"
78
"encoding/json"
89
"fmt"
@@ -42,6 +43,7 @@ func init() {
4243
type Worker struct {
4344
App app.App
4445
StartedAt time.Time
46+
Secret string
4547
Logger *slog.Logger
4648

4749
port int
@@ -54,6 +56,7 @@ func NewWorker(app app.App, logger *slog.Logger) *Worker {
5456
worker := &Worker{
5557
App: app,
5658
Logger: logger,
59+
Secret: rand.Text(),
5760
}
5861

5962
return worker
@@ -123,6 +126,7 @@ func (me *Worker) Start() error {
123126
command.Env = me.App.Env()
124127
command.Env = append(command.Env, fmt.Sprintf("SMALLWEB_PORT=%d", port))
125128
command.Env = append(command.Env, fmt.Sprintf("SMALLWEB_ENTRYPOINT=%s", me.App.Entrypoint()))
129+
command.Env = append(command.Env, fmt.Sprintf("SMALLWEB_SECRET=%s", me.Secret))
126130

127131
stdoutPipe, err := command.StdoutPipe()
128132
if err != nil {

0 commit comments

Comments
 (0)