Move static assets to within srv

main
Brian Picciano 2 years ago
parent 3cdee89c96
commit 16cfbd1915
  1. 10
      Makefile
  2. 20
      default.nix
  3. 2
      srv-dev-env.sh
  4. 4
      srv/default.nix
  5. 116
      srv/src/http/api.go
  6. 4
      srv/src/http/static/api.js
  7. 0
      srv/src/http/static/component-oriented-design/v1/main.go
  8. 0
      srv/src/http/static/component-oriented-design/v1/main.md
  9. 0
      srv/src/http/static/component-oriented-design/v1/main_test.go
  10. 0
      srv/src/http/static/component-oriented-design/v1/main_test.md
  11. 0
      srv/src/http/static/component-oriented-design/v2/main.go
  12. 0
      srv/src/http/static/component-oriented-design/v2/main.md
  13. 0
      srv/src/http/static/component-oriented-design/v3/main.go
  14. 0
      srv/src/http/static/component-oriented-design/v3/main.md
  15. 0
      srv/src/http/static/dog-money.png
  16. 0
      srv/src/http/static/fontawesome/LICENSE.txt
  17. 0
      srv/src/http/static/fontawesome/css/all.css
  18. 0
      srv/src/http/static/fontawesome/css/all.min.css
  19. 0
      srv/src/http/static/fontawesome/css/brands.css
  20. 0
      srv/src/http/static/fontawesome/css/brands.min.css
  21. 0
      srv/src/http/static/fontawesome/css/fontawesome.css
  22. 0
      srv/src/http/static/fontawesome/css/fontawesome.min.css
  23. 0
      srv/src/http/static/fontawesome/css/regular.css
  24. 0
      srv/src/http/static/fontawesome/css/regular.min.css
  25. 0
      srv/src/http/static/fontawesome/css/solid.css
  26. 0
      srv/src/http/static/fontawesome/css/solid.min.css
  27. 0
      srv/src/http/static/fontawesome/css/svg-with-js.css
  28. 0
      srv/src/http/static/fontawesome/css/svg-with-js.min.css
  29. 0
      srv/src/http/static/fontawesome/css/v4-shims.css
  30. 0
      srv/src/http/static/fontawesome/css/v4-shims.min.css
  31. 0
      srv/src/http/static/fontawesome/webfonts/fa-brands-400.eot
  32. 0
      srv/src/http/static/fontawesome/webfonts/fa-brands-400.svg
  33. 0
      srv/src/http/static/fontawesome/webfonts/fa-brands-400.ttf
  34. 0
      srv/src/http/static/fontawesome/webfonts/fa-brands-400.woff
  35. 0
      srv/src/http/static/fontawesome/webfonts/fa-brands-400.woff2
  36. 0
      srv/src/http/static/fontawesome/webfonts/fa-regular-400.eot
  37. 0
      srv/src/http/static/fontawesome/webfonts/fa-regular-400.svg
  38. 0
      srv/src/http/static/fontawesome/webfonts/fa-regular-400.ttf
  39. 0
      srv/src/http/static/fontawesome/webfonts/fa-regular-400.woff
  40. 0
      srv/src/http/static/fontawesome/webfonts/fa-regular-400.woff2
  41. 0
      srv/src/http/static/fontawesome/webfonts/fa-solid-900.eot
  42. 0
      srv/src/http/static/fontawesome/webfonts/fa-solid-900.svg
  43. 0
      srv/src/http/static/fontawesome/webfonts/fa-solid-900.ttf
  44. 0
      srv/src/http/static/fontawesome/webfonts/fa-solid-900.woff
  45. 0
      srv/src/http/static/fontawesome/webfonts/fa-solid-900.woff2
  46. 0
      srv/src/http/static/friendly.css
  47. 0
      srv/src/http/static/maddy-vps/success.png
  48. 0
      srv/src/http/static/main.css
  49. 0
      srv/src/http/static/markov/Makefile
  50. 0
      srv/src/http/static/markov/Makefile.md
  51. 0
      srv/src/http/static/markov/markov.nix
  52. 0
      srv/src/http/static/markov/markov.nix.md
  53. 0
      srv/src/http/static/normalize.css
  54. 0
      srv/src/http/static/overpass-regular.woff
  55. 0
      srv/src/http/static/qrcode.min.js
  56. 0
      srv/src/http/static/skeleton.css
  57. 0
      srv/src/http/static/solvePow.js
  58. 0
      srv/src/http/static/trading-in-the-rain/CW.js
  59. 0
      srv/src/http/static/trading-in-the-rain/Distributor.js
  60. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/LICENSE.txt
  61. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/inc/shim/Base64.js
  62. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/inc/shim/Base64binary.js
  63. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/inc/shim/WebAudioAPI.js
  64. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/inc/shim/WebMIDIAPI.js
  65. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/audioDetect.js
  66. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/gm.js
  67. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/loader.js
  68. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/player.js
  69. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/plugin.audiotag.js
  70. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/plugin.webaudio.js
  71. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/plugin.webmidi.js
  72. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/midi/synesthesia.js
  73. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/util/dom_request_script.js
  74. 0
      srv/src/http/static/trading-in-the-rain/MIDI.js/js/util/dom_request_xhr.js
  75. 2
      srv/src/http/static/trading-in-the-rain/MusicBox.js
  76. 0
      srv/src/http/static/trading-in-the-rain/RainCanvas.js
  77. 0
      srv/src/http/static/trading-in-the-rain/SeriesComposer.js
  78. 0
      srv/src/http/static/trading-in-the-rain/key.gpg
  79. 0
      srv/src/http/static/trading-in-the-rain/main.js
  80. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3.js
  81. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A0.mp3
  82. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A1.mp3
  83. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A2.mp3
  84. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A3.mp3
  85. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A4.mp3
  86. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A5.mp3
  87. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A6.mp3
  88. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/A7.mp3
  89. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab1.mp3
  90. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab2.mp3
  91. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab3.mp3
  92. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab4.mp3
  93. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab5.mp3
  94. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab6.mp3
  95. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/Ab7.mp3
  96. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/B0.mp3
  97. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/B1.mp3
  98. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/B2.mp3
  99. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/B3.mp3
  100. 0
      srv/src/http/static/trading-in-the-rain/soundfont/acoustic_grand_piano-mp3/B4.mp3
  101. Some files were not shown because too many files have changed in this diff Show More

@ -24,13 +24,3 @@ srv.dev-shell:
srv.shell:
nix-shell -A srv.shellWithBuild --arg baseConfig '(import ${CONFIG})' \
--command 'cd srv/src; return'
# TODO static is on the way out, these aren't well supported
static.serve:
nix-shell -A static.shell --run 'cd static; static-serve'
static.depShell:
nix-shell -A static.depShell --command 'cd static; return'
static.lock:
nix-shell -A static.depShell --run 'bundler lock; bundix; rm -rf .bundle vendor'

@ -7,7 +7,7 @@
}) {},
baseConfig ? import ./config.nix,
baseSkipServices ? [],
skipServices ? [],
}: rec {
@ -17,17 +17,8 @@
redisListenPath = "${config.runDir}/redis";
};
skipServices = baseSkipServices ++ (
if baseConfig.staticProxyURL == ""
then [ "static" ]
else []
);
static = (import ./static) { inherit pkgs; };
srv = pkgs.callPackage (import ./srv) {
inherit config;
staticBuild=static.build;
};
redisCfg = pkgs.writeText "mediocre-blog-redisCfg" ''
@ -59,13 +50,6 @@
numprocesses = 1
'';
staticCircusCfg = ''
[watcher:static]
cmd = ${static.serve}/bin/static-serve
numprocesses = 1
working_dir = ./static
'';
circusCfg = pkgs.writeText "mediocre-blog-circusCfg" ''
[circus]
endpoint = tcp://127.0.0.1:0
@ -74,8 +58,6 @@
${if (!builtins.elem "srv" skipServices) then srvCircusCfg else ""}
${if (!builtins.elem "redis" skipServices) then redisCircusCfg else ""}
${if (!builtins.elem "static" skipServices) then staticCircusCfg else ""}
'';
entrypoint = pkgs.writeScript "mediocre-blog-entrypoint" ''

@ -11,7 +11,7 @@ test_cfg="(import ./config.nix) // {
entrypoint=$(nix-build --no-out-link -A entrypoint \
--arg baseConfig "$test_cfg" \
--arg baseSkipServices '["srv"]')
--arg skipServices '["srv"]')
$entrypoint &
trap "kill $!; wait; rm -rf $test_dir" EXIT

@ -7,7 +7,6 @@
stdenv,
config,
staticBuild,
}: rec {
init = writeText "mediocre-blog-srv-init" ''
@ -26,9 +25,6 @@
# pow
export MEDIOCRE_BLOG_POW_SECRET="${config.powSecret}"
# static proxy
export MEDIOCRE_BLOG_STATIC_DIR="${staticBuild}"
# listening
export MEDIOCRE_BLOG_LISTEN_PROTO="${config.listenProto}"
export MEDIOCRE_BLOG_LISTEN_ADDR="${config.listenAddr}"

@ -3,13 +3,12 @@ package http
import (
"context"
"embed"
"errors"
"fmt"
"html/template"
"net"
"net/http"
"net/http/httputil"
"net/url"
"os"
"github.com/mediocregopher/blog.mediocregopher.com/srv/cfg"
@ -22,6 +21,9 @@ import (
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
)
//go:embed static
var staticFS embed.FS
// Params are used to instantiate a new API instance. All fields are required
// unless otherwise noted.
type Params struct {
@ -45,16 +47,6 @@ type Params struct {
// supported.
ListenProto, ListenAddr string
// StaticDir and StaticProxy are mutually exclusive.
//
// If StaticDir is set then that directory on the filesystem will be used to
// serve the static site.
//
// Otherwise if StaticProxy is set all requests for the static site will be
// reverse-proxied there.
StaticDir string
StaticProxy *url.URL
// AuthUsers keys are usernames which are allowed to edit server-side data,
// and the values are the password hash which accompanies those users. The
// password hash must have been produced by NewPasswordHash.
@ -63,39 +55,14 @@ type Params struct {
// SetupCfg implement the cfg.Cfger interface.
func (p *Params) SetupCfg(cfg *cfg.Cfg) {
cfg.StringVar(&p.ListenProto, "listen-proto", "tcp", "Protocol to listen for HTTP requests with")
cfg.StringVar(&p.ListenAddr, "listen-addr", ":4000", "Address/path to listen for HTTP requests on")
cfg.StringVar(&p.StaticDir, "static-dir", "", "Directory from which static files are served (mutually exclusive with -static-proxy-url)")
staticProxyURLStr := cfg.String("static-proxy-url", "", "HTTP address from which static files are served (mutually exclusive with -static-dir)")
cfg.OnInit(func(ctx context.Context) error {
if *staticProxyURLStr != "" {
var err error
if p.StaticProxy, err = url.Parse(*staticProxyURLStr); err != nil {
return fmt.Errorf("parsing -static-proxy-url: %w", err)
}
} else if p.StaticDir == "" {
return errors.New("-static-dir or -static-proxy-url is required")
}
return nil
})
}
// Annotate implements mctx.Annotator interface.
func (p *Params) Annotate(a mctx.Annotations) {
a["listenProto"] = p.ListenProto
a["listenAddr"] = p.ListenAddr
if p.StaticProxy != nil {
a["staticProxy"] = p.StaticProxy.String()
return
}
a["staticDir"] = p.StaticDir
}
// API will listen on the port configured for it, and serve HTTP requests for
@ -156,15 +123,6 @@ func (a *api) Shutdown(ctx context.Context) error {
func (a *api) handler() http.Handler {
var staticHandler http.Handler
if a.params.StaticDir != "" {
staticHandler = http.FileServer(http.Dir(a.params.StaticDir))
} else {
staticHandler = httputil.NewSingleHostReverseProxy(a.params.StaticProxy)
}
// sugar
requirePow := func(h http.Handler) http.Handler {
return a.requirePowMiddleware(h)
}
@ -185,8 +143,6 @@ func (a *api) handler() http.Handler {
mux := http.NewServeMux()
mux.Handle("/", staticHandler)
{
apiMux := http.NewServeMux()
apiMux.Handle("/pow/challenge", a.newPowChallengeHandler())
@ -209,39 +165,37 @@ func (a *api) handler() http.Handler {
mux.Handle("/api/", http.StripPrefix("/api", formMiddleware(apiMux)))
}
{
v2Mux := http.NewServeMux()
v2Mux.Handle("/follow.html", a.renderDumbTplHandler("follow.html"))
v2Mux.Handle("/posts/", http.StripPrefix("/posts",
apiutil.MethodMux(map[string]http.Handler{
"GET": a.renderPostHandler(),
"EDIT": a.editPostHandler(),
"POST": authMiddleware(auther,
formMiddleware(a.postPostHandler()),
),
"DELETE": authMiddleware(auther,
formMiddleware(a.deletePostHandler()),
),
"PREVIEW": authMiddleware(auther,
formMiddleware(a.previewPostHandler()),
),
}),
))
v2Mux.Handle("/assets/", http.StripPrefix("/assets",
apiutil.MethodMux(map[string]http.Handler{
"GET": a.getPostAssetHandler(),
"POST": authMiddleware(auther,
formMiddleware(a.postPostAssetHandler()),
),
"DELETE": authMiddleware(auther,
formMiddleware(a.deletePostAssetHandler()),
),
}),
))
v2Mux.Handle("/", a.renderIndexHandler())
mux.Handle("/v2/", http.StripPrefix("/v2", v2Mux))
}
mux.Handle("/posts/", http.StripPrefix("/posts",
apiutil.MethodMux(map[string]http.Handler{
"GET": a.renderPostHandler(),
"EDIT": a.editPostHandler(),
"POST": authMiddleware(auther,
formMiddleware(a.postPostHandler()),
),
"DELETE": authMiddleware(auther,
formMiddleware(a.deletePostHandler()),
),
"PREVIEW": authMiddleware(auther,
formMiddleware(a.previewPostHandler()),
),
}),
))
mux.Handle("/assets/", http.StripPrefix("/assets",
apiutil.MethodMux(map[string]http.Handler{
"GET": a.getPostAssetHandler(),
"POST": authMiddleware(auther,
formMiddleware(a.postPostAssetHandler()),
),
"DELETE": authMiddleware(auther,
formMiddleware(a.deletePostAssetHandler()),
),
}),
))
mux.Handle("/static/", http.FileServer(http.FS(staticFS)))
mux.Handle("/follow.html", a.renderDumbTplHandler("follow.html"))
mux.Handle("/", a.renderIndexHandler())
var globalHandler http.Handler = mux
globalHandler = setCSRFMiddleware(globalHandler)

@ -1,4 +1,4 @@
import * as utils from "/assets/utils.js";
import * as utils from "/static/utils.js";
const csrfTokenCookie = "csrf_token";
@ -35,7 +35,7 @@ const solvePow = async () => {
const res = await call('/api/pow/challenge');
const worker = new Worker('/assets/solvePow.js');
const worker = new Worker('/static/solvePow.js');
const p = new Promise((resolve, reject) => {
worker.postMessage({seedHex: res.seed, target: res.target});

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

@ -1,7 +1,7 @@
var midiLoaded = false;
function loadMIDI() {
MIDI.loadPlugin({
soundfontUrl: "/assets/trading-in-the-rain/soundfont/",
soundfontUrl: "/static/trading-in-the-rain/soundfont/",
instrument: "acoustic_grand_piano",
onprogress: (state, progress) => {
console.log("MIDI loading...", progress*100, "%");

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save