From 8d2e649b4dae4523d9c0ac36d5dfd31409447be4 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 14 Mar 2023 17:30:15 -0500 Subject: [PATCH] Create build step for the web server (#289) * Create build step for the web server * Update bskyweb routes and 404 behavior --- app.json | 2 +- bskyweb/README.md | 3 +- bskyweb/cmd/bskyweb/server.go | 9 ++- bskyweb/templates/base.html | 120 ++++++++++++++++++++++++++--- bskyweb/templates/error.html | 30 +++++--- bskyweb/templates/scripts.html | 2 + package.json | 1 + scripts/post-web-build.js | 27 +++++++ src/view/shell/desktop/LeftNav.tsx | 2 +- 9 files changed, 169 insertions(+), 27 deletions(-) create mode 100644 bskyweb/templates/scripts.html create mode 100644 scripts/post-web-build.js diff --git a/app.json b/app.json index 13e35d9a..ebf4224b 100644 --- a/app.json +++ b/app.json @@ -7,7 +7,7 @@ "icon": "./assets/icon.png", "userInterfaceStyle": "light", "splash": { - "image": "./assets/splash.png", + "image": "./assets/cloud-splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, diff --git a/bskyweb/README.md b/bskyweb/README.md index 86bc1686..2c381495 100644 --- a/bskyweb/README.md +++ b/bskyweb/README.md @@ -20,8 +20,7 @@ like: Then build and copy over the big 'ol `bundle.web.js` file: # in the top level of this repo - yarn webpack build --config ./web/webpack.config.js -d inline-source-map --color - cp dist/bundle.web.js bskyweb/static/ + yarn build-web ### Golang Daemon diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index 6a8a8888..7ae0fb54 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -94,20 +94,23 @@ func serve(cctx *cli.Context) error { // configure routes e.File("/robots.txt", "static/robots.txt") e.Static("/static", "static") + e.Static("/static/js", "../web-build/static/js") e.GET("/", server.WebHome) // generic routes - e.GET("/contacts", server.WebGeneric) e.GET("/search", server.WebGeneric) e.GET("/notifications", server.WebGeneric) e.GET("/settings", server.WebGeneric) - e.GET("/settings", server.WebGeneric) + e.GET("/sys/debug", server.WebGeneric) + e.GET("/sys/log", server.WebGeneric) + e.GET("/support", server.WebGeneric) + e.GET("/support/privacy", server.WebGeneric) // profile endpoints; only first populates info e.GET("/profile/:handle", server.WebProfile) e.GET("/profile/:handle/follows", server.WebGeneric) - e.GET("/profile/:handle/following", server.WebGeneric) + e.GET("/profile/:handle/followers", server.WebGeneric) // post endpoints; only first populates info e.GET("/profile/:handle/post/:rkey", server.WebPost) diff --git a/bskyweb/templates/base.html b/bskyweb/templates/base.html index 024e48d6..05c9becc 100644 --- a/bskyweb/templates/base.html +++ b/bskyweb/templates/base.html @@ -2,21 +2,120 @@ - + + {%- block head_title -%}Bluesky{%- endblock -%} + + - {% block head_bundle -%}{%- endblock %} + {% include "scripts.html" %} @@ -38,14 +137,13 @@ {%- block body_all %} -
+
{% endblock -%} diff --git a/bskyweb/templates/error.html b/bskyweb/templates/error.html index e40d8c4a..f8fdd290 100644 --- a/bskyweb/templates/error.html +++ b/bskyweb/templates/error.html @@ -2,14 +2,26 @@ {% block head_title %}Error {{ statusCode }} - Bluesky{% endblock %} -{# don't include the bundle on error pages #} -{% block head_bundle %}{% endblock %} - -{% block body_all %} - {% if statusCode == 404 %} -

404: Not Found

- {% else %} -

{{ statusCode }}: Server Error

-

Sorry about that! Our Status Page might have more context. +{% block noscript_extra %} + {%- if statusCode == 404 %} +

404: Not Found

{% endif %} {% endblock %} + + +{# don't include the bundle on non-404 error pages #} +{% block head_bundle %} + {% if statusCode == 404 %} + {{ super() }} + {% else %} + {% endif %} +{% endblock %} + +{%- block body_all %} + {% if statusCode == 404 %} + {{ super() }} + {% else %} +

{{ statusCode }}: Server Error

+

Sorry about that! Our Status Page might have more context. + {% endif %} +{% endblock -%} \ No newline at end of file diff --git a/bskyweb/templates/scripts.html b/bskyweb/templates/scripts.html new file mode 100644 index 00000000..30826bfb --- /dev/null +++ b/bskyweb/templates/scripts.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/package.json b/package.json index f7264d32..30f2c354 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", + "build-web": "expo export:web && node ./scripts/post-web-build.js", "start": "expo start --dev-client", "clean-cache": "rm -rf node_modules/.cache/babel-loader/*", "test": "jest --forceExit --testTimeout=20000 --bail", diff --git a/scripts/post-web-build.js b/scripts/post-web-build.js new file mode 100644 index 00000000..5db37885 --- /dev/null +++ b/scripts/post-web-build.js @@ -0,0 +1,27 @@ +const path = require('path') +const fs = require('fs') + +const projectRoot = path.join(__dirname, '..') +const webBuildJs = path.join(projectRoot, 'web-build', 'static', 'js') +const templateFile = path.join( + projectRoot, + 'bskyweb', + 'templates', + 'scripts.html', +) + +const jsFiles = fs.readdirSync(webBuildJs).filter(name => name.endsWith('.js')) +jsFiles.sort((a, b) => { + // make sure main is written last + if (a.startsWith('main')) return 1 + if (b.startsWith('main')) return -1 + return a.localeCompare(b) +}) + +console.log(`Found ${jsFiles.length} js files in web-build`) +console.log(`Writing ${templateFile}`) + +const outputFile = jsFiles + .map(name => ``) + .join('\n') +fs.writeFileSync(templateFile, outputFile) diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index 65757b07..2c1cb667 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -238,7 +238,7 @@ const styles = StyleSheet.create({ flexDirection: 'row', alignItems: 'center', justifyContent: 'center', - width: 136, + width: 138, borderRadius: 24, paddingVertical: 10, paddingHorizontal: 16,