Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #5610 from bluesky-social/static_asset_cdn

Serve static assets from a CDN host if provided

authored by

Jaz and committed by
GitHub
6dfd57e6 3fb14d18

+47 -30
+7
bskyweb/cmd/bskyweb/main.go
··· 87 87 Value: cli.NewStringSlice("https://bsky.app", "https://main.bsky.dev", "https://app.staging.bsky.dev"), 88 88 EnvVars: []string{"CORS_ALLOWED_ORIGINS"}, 89 89 }, 90 + &cli.StringFlag{ 91 + Name: "static-cdn-host", 92 + Usage: "scheme, hostname, and port of static content CDN, don't end with a slash", 93 + Required: false, 94 + Value: "", 95 + EnvVars: []string{"STATIC_CDN_HOST"}, 96 + }, 90 97 }, 91 98 }, 92 99 }
+30 -20
bskyweb/cmd/bskyweb/server.go
··· 41 41 } 42 42 43 43 type Config struct { 44 - debug bool 45 - httpAddress string 46 - appviewHost string 47 - ogcardHost string 48 - linkHost string 49 - ipccHost string 44 + debug bool 45 + httpAddress string 46 + appviewHost string 47 + ogcardHost string 48 + linkHost string 49 + ipccHost string 50 + staticCDNHost string 50 51 } 51 52 52 53 func serve(cctx *cli.Context) error { ··· 58 59 ipccHost := cctx.String("ipcc-host") 59 60 basicAuthPassword := cctx.String("basic-auth-password") 60 61 corsOrigins := cctx.StringSlice("cors-allowed-origins") 62 + staticCDNHost := cctx.String("static-cdn-host") 63 + staticCDNHost = strings.TrimSuffix(staticCDNHost, "/") 61 64 62 65 // Echo 63 66 e := echo.New() ··· 94 97 echo: e, 95 98 xrpcc: xrpcc, 96 99 cfg: &Config{ 97 - debug: debug, 98 - httpAddress: httpAddress, 99 - appviewHost: appviewHost, 100 - ogcardHost: ogcardHost, 101 - linkHost: linkHost, 102 - ipccHost: ipccHost, 100 + debug: debug, 101 + httpAddress: httpAddress, 102 + appviewHost: appviewHost, 103 + ogcardHost: ogcardHost, 104 + linkHost: linkHost, 105 + ipccHost: ipccHost, 106 + staticCDNHost: staticCDNHost, 103 107 }, 104 108 } 105 109 ··· 333 337 return srv.httpd.Shutdown(ctx) 334 338 } 335 339 340 + // NewTemplateContext returns a new pongo2 context with some default values. 341 + func (srv *Server) NewTemplateContext() pongo2.Context { 342 + return pongo2.Context{ 343 + "staticCDNHost": srv.cfg.staticCDNHost, 344 + } 345 + } 346 + 336 347 func (srv *Server) errorHandler(err error, c echo.Context) { 337 348 code := http.StatusInternalServerError 338 349 if he, ok := err.(*echo.HTTPError); ok { 339 350 code = he.Code 340 351 } 341 352 c.Logger().Error(err) 342 - data := pongo2.Context{ 343 - "statusCode": code, 344 - } 353 + data := srv.NewTemplateContext() 354 + data["statusCode"] = code 345 355 c.Render(code, "error.html", data) 346 356 } 347 357 ··· 385 395 386 396 // handler for endpoint that have no specific server-side handling 387 397 func (srv *Server) WebGeneric(c echo.Context) error { 388 - data := pongo2.Context{} 398 + data := srv.NewTemplateContext() 389 399 return c.Render(http.StatusOK, "base.html", data) 390 400 } 391 401 392 402 func (srv *Server) WebHome(c echo.Context) error { 393 - data := pongo2.Context{} 403 + data := srv.NewTemplateContext() 394 404 return c.Render(http.StatusOK, "home.html", data) 395 405 } 396 406 397 407 func (srv *Server) WebPost(c echo.Context) error { 398 408 ctx := c.Request().Context() 399 - data := pongo2.Context{} 409 + data := srv.NewTemplateContext() 400 410 401 411 // sanity check arguments. don't 4xx, just let app handle if not expected format 402 412 rkeyParam := c.Param("rkey") ··· 471 481 func (srv *Server) WebStarterPack(c echo.Context) error { 472 482 req := c.Request() 473 483 ctx := req.Context() 474 - data := pongo2.Context{} 484 + data := srv.NewTemplateContext() 475 485 data["requestURI"] = fmt.Sprintf("https://%s%s", req.Host, req.URL.Path) 476 486 // sanity check arguments. don't 4xx, just let app handle if not expected format 477 487 rkeyParam := c.Param("rkey") ··· 509 519 510 520 func (srv *Server) WebProfile(c echo.Context) error { 511 521 ctx := c.Request().Context() 512 - data := pongo2.Context{} 522 + data := srv.NewTemplateContext() 513 523 514 524 // sanity check arguments. don't 4xx, just let app handle if not expected format 515 525 handleOrDIDParam := c.Param("handleOrDID")
+8 -8
bskyweb/templates/base.html
··· 13 13 14 14 <!-- Hello Humans! API docs at https://atproto.com --> 15 15 16 - <link rel="preload" as="font" type="font/ttf" href="/static/media/InterVariable.c9f788f6e7ebaec75d7c.ttf"> 17 - <link rel="preload" as="font" type="font/ttf" href="/static/media/InterVariable-Italic.55d6a3f35e9b605ba6f4.ttf"> 16 + <link rel="preload" as="font" type="font/ttf" href="{{ staticCDNHost }}/static/media/InterVariable.c9f788f6e7ebaec75d7c.ttf"> 17 + <link rel="preload" as="font" type="font/ttf" href="{{ staticCDNHost }}/static/media/InterVariable-Italic.55d6a3f35e9b605ba6f4.ttf"> 18 18 19 19 <style> 20 20 /** ··· 26 26 */ 27 27 @font-face { 28 28 font-family: 'InterVariable'; 29 - src: url(/static/media/InterVariable.c9f788f6e7ebaec75d7c.ttf) format('truetype'); 29 + src: url("{{ staticCDNHost }}/static/media/InterVariable.c9f788f6e7ebaec75d7c.ttf") format('truetype'); 30 30 font-weight: 300 1000; 31 31 font-style: normal; 32 32 font-display: swap; 33 33 } 34 34 @font-face { 35 35 font-family: 'InterVariableItalic'; 36 - src: url(/static/media/InterVariable-Italic.55d6a3f35e9b605ba6f4.ttf) format('truetype'); 36 + src: url("{{ staticCDNHost }}/static/media/InterVariable-Italic.55d6a3f35e9b605ba6f4.ttf") format('truetype'); 37 37 font-weight: 300 1000; 38 38 font-style: italic; 39 39 font-display: swap; ··· 78 78 </style> 79 79 80 80 {% include "scripts.html" %} 81 - <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png"> 82 - <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png"> 83 - <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png"> 84 - <link rel="mask-icon" href="/static/safari-pinned-tab.svg" color="#1185fe"> 81 + <link rel="apple-touch-icon" sizes="180x180" href="{{ staticCDNHost }}/static/apple-touch-icon.png"> 82 + <link rel="icon" type="image/png" sizes="32x32" href="{{ staticCDNHost }}/static/favicon-32x32.png"> 83 + <link rel="icon" type="image/png" sizes="16x16" href="{{ staticCDNHost }}/static/favicon-16x16.png"> 84 + <link rel="mask-icon" href="{{ staticCDNHost }}/static/safari-pinned-tab.svg" color="#1185fe"> 85 85 <meta name="theme-color"> 86 86 <meta name="application-name" content="Bluesky"> 87 87 <meta name="generator" content="bskyweb">
+2 -2
scripts/post-web-build.js
··· 23 23 const ext = path.extname(file) 24 24 25 25 if (ext === '.js') { 26 - return `<script defer="defer" src="/static/js/${file}"></script>` 26 + return `<script defer="defer" src="{{ staticCDNHost }}/static/js/${file}"></script>` 27 27 } 28 28 if (ext === '.css') { 29 - return `<link rel="stylesheet" href="/static/css/${file}">` 29 + return `<link rel="stylesheet" href="{{ staticCDNHost }}/static/css/${file}">` 30 30 } 31 31 32 32 return ''