Compare commits

..

No commits in common. "e20dc64d0d68108a8a899a4744d4d1dd0aff055e" and "2fa72b5cf46c905a0782938e54cc8260dbed2bbc" have entirely different histories.

7 changed files with 26 additions and 54 deletions

@ -1,4 +1,4 @@
# 📜 pages
# pages
`pages` provides web application / static site hosting with built-in support for simple analytics via [Prometheus][] and
[Grafana][].

@ -18,7 +18,6 @@ package commands
import (
"context"
"mime"
"net/http"
"github.com/urfave/cli/v2"
@ -52,20 +51,8 @@ var (
Action: func(ctx *cli.Context) error {
log := zaputil.Extract(ctx.Context)
// additional mime-types that need to be explicitly registered
_ = mime.AddExtensionType(".woff2", "application/font-woff2")
_ = mime.AddExtensionType(".woff", "application/font-woff")
_ = mime.AddExtensionType(".ttf", "font/ttf")
_ = mime.AddExtensionType(".yaml", "application/yaml")
_ = mime.AddExtensionType(".yml", "application/yaml")
_ = mime.AddExtensionType(".json", "application/json")
gitService, err := git.NewService(hostConfig.Git)
if err != nil {
return err
}
err = gitService.Load(ctx.Context)
gitService := git.NewService(hostConfig.Git)
err := gitService.Load(ctx.Context)
if err != nil {
return err
}

@ -58,10 +58,6 @@ type httpFile struct {
file billy.File
}
func (f *httpFile) Seek(offset int64, whence int) (int64, error) {
return f.file.Seek(offset, whence)
}
func (f *httpFile) Stat() (fs.FileInfo, error) {
return f.fileInfo, nil
}

@ -18,10 +18,9 @@ package git
import (
"context"
"os"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/http"
@ -42,14 +41,11 @@ type Config struct {
}
// NewService constructs a Service that manages the underlying git repository.
func NewService(config Config) (*Service, error) {
temp, err := os.MkdirTemp(os.TempDir(), "pages-*")
if err != nil {
return nil, err
}
func NewService(config Config) *Service {
options := &git.CloneOptions{
URL: config.URL,
URL: config.URL,
Depth: 1,
SingleBranch: true,
}
if config.Username != "" && config.Password != "" {
@ -69,8 +65,8 @@ func NewService(config Config) (*Service, error) {
return &Service{
options: options,
Store: memory.NewStorage(),
FS: osfs.New(temp),
}, nil
FS: memfs.New(),
}
}
// Service encapsulates operations that can be performed against the target git repository.
@ -102,7 +98,7 @@ func (s *Service) Sync(ctx context.Context) error {
return errors.Wrap(err, "failed to obtain worktree")
}
err = wt.PullContext(ctx, &git.PullOptions{
_ = wt.PullContext(ctx, &git.PullOptions{
ReferenceName: s.options.ReferenceName,
SingleBranch: s.options.SingleBranch,
Depth: s.options.Depth,
@ -110,11 +106,5 @@ func (s *Service) Sync(ctx context.Context) error {
Force: true,
})
switch {
case errors.Is(err, git.NoErrAlreadyUpToDate):
case err != nil:
zaputil.Extract(ctx).Error("failed to pull", zap.Error(err))
}
return nil
}

@ -20,6 +20,7 @@ import (
"context"
"net"
"net/http"
"path"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
@ -94,15 +95,9 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
public.Use(
session.Middleware(
session.Exclusions(exclusions...),
session.JavaScriptPath("/pages.js"),
session.JavaScriptPath(path.Join(config.Session.Prefix, "pages.js")),
),
)
var handler http.Handler = session.Handler()
handler = http.StripPrefix(config.Session.Prefix, handler)
public.Handle("/pages.js", web.Handler()).Methods(http.MethodGet)
public.PathPrefix(config.Session.Prefix).Handler(handler)
}
admin := public.PathPrefix(config.Admin.Prefix).Subrouter()
@ -116,6 +111,15 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) {
})
}
{
var handler http.Handler = session.Handler()
handler = http.StripPrefix(config.Session.Prefix, handler)
session := public.PathPrefix(config.Session.Prefix).Subrouter()
session.HandleFunc("/pages.js", web.Handler()).Methods(http.MethodGet)
session.Handle("/", handler)
}
return &Server{
AdminMux: admin,

@ -21,9 +21,7 @@ import (
"time"
"github.com/gorilla/websocket"
"go.uber.org/zap"
"github.com/mjpitz/myago/zaputil"
"github.com/mjpitz/pages/internal/geoip"
"github.com/mjpitz/pages/internal/metrics"
)
@ -47,11 +45,9 @@ type Handle struct {
}
func (h *Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log := zaputil.Extract(r.Context())
conn, err := h.upgrader.Upgrade(w, r, nil)
if err != nil {
log.Error("failed to upgrade connection", zap.Error(err))
// log
return
}
@ -74,6 +70,7 @@ func (h *Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = conn.ReadJSON(&req)
if err != nil {
// log
return
}
}

@ -18,13 +18,11 @@
import {ulid} from 'ulid';
const secure = window.location.protocol === "https:";
const protocol = secure ? "wss:" : "ws:";
const sessionPrefix = "/_session";
const domain = window.location.host + (secure ? ":443" : "");
const domain = window.location.host;
async function main() {
const ws = new WebSocket(`${protocol}//${domain}${sessionPrefix}${window.location.pathname}`);
const ws = new WebSocket(`ws://${domain}${sessionPrefix}${window.location.pathname}`);
const message = `{"ID":"${ulid()}","FullName":"ping"}`
let id = null;