Skip to content

Commit d82fa6b

Browse files
committed
add global data dir
1 parent b9e7923 commit d82fa6b

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

example/.smallweb/config.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"$schema": "../../schemas/config.schema.json",
33
"domain": "smallweb.live",
44
"apps": {
5+
"example-repo": {
6+
"privacy": "public"
7+
},
58
"example-cron": {
69
"crons": [
710
{

example/unstorage/deno.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"lock": false,
3+
"imports": {
4+
"unstorage": "npm:unstorage@^2.0.0-alpha.4"
5+
}
6+
}

example/unstorage/main.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createStorage } from "unstorage"
2+
import fsDriver from "unstorage/drivers/fs-lite"
3+
import { createStorageHandler } from "unstorage/server";
4+
5+
const { SMALLWEB_DATA_DIR } = Deno.env.toObject();
6+
7+
if (!SMALLWEB_DATA_DIR) {
8+
console.error("SMALLWEB_DATA_DIR is not set.");
9+
Deno.exit(1);
10+
}
11+
12+
const storage = createStorage({
13+
driver: fsDriver({
14+
base: SMALLWEB_DATA_DIR
15+
})
16+
})
17+
18+
export default {
19+
fetch: createStorageHandler(storage),
20+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/knadh/koanf/v2 v2.2.2
1616
github.com/mattn/go-isatty v0.0.20
1717
github.com/spf13/cobra v1.9.1
18-
golang.org/x/net v0.43.0
18+
golang.org/x/net v0.43.0 // indirect
1919
golang.org/x/term v0.34.0
2020
)
2121

internal/api/api.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/http/cgi"
78
"os"
@@ -15,7 +16,6 @@ import (
1516
"github.com/go-chi/hostrouter"
1617
"github.com/pomdtr/smallweb/internal/app"
1718
"github.com/pomdtr/smallweb/internal/utils"
18-
"golang.org/x/net/webdav"
1919
)
2020

2121
type GetBlobsOutput struct {
@@ -44,7 +44,6 @@ func NewHandler(conf *utils.Config) http.Handler {
4444
r := chi.NewRouter()
4545
hr := hostrouter.New()
4646

47-
hr.Map("webdav.localhost", webdavRouter(conf))
4847
hr.Map("api.localhost", apiRouter(conf))
4948
hr.Map("git.localhost", gitRouter(conf))
5049
hr.Map("*", catchAllRouter())
@@ -54,17 +53,6 @@ func NewHandler(conf *utils.Config) http.Handler {
5453
return r
5554
}
5655

57-
func webdavRouter(conf *utils.Config) chi.Router {
58-
r := chi.NewRouter()
59-
60-
r.Handle("/*", &webdav.Handler{
61-
FileSystem: webdav.Dir(conf.String("dir")),
62-
LockSystem: webdav.NewMemLS(),
63-
})
64-
65-
return r
66-
}
67-
6856
func apiRouter(conf *utils.Config) chi.Router {
6957
r := chi.NewRouter()
7058

@@ -152,7 +140,13 @@ func gitRouter(conf *utils.Config) chi.Router {
152140
},
153141
}
154142

155-
r.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
143+
r.HandleFunc("/{app}/*", func(w http.ResponseWriter, r *http.Request) {
144+
appname := chi.URLParam(r, "app")
145+
if conf.String(fmt.Sprintf("apps.%s.privacy", appname)) != "public" {
146+
http.Error(w, "Not found", http.StatusNotFound)
147+
return
148+
}
149+
156150
if strings.HasSuffix(r.URL.Path, "/git-receive-pack") {
157151
http.Error(w, "pushes are disabled", http.StatusForbidden)
158152
return

0 commit comments

Comments
 (0)