Browse Source
* WIP with admin bundling * Current state of the admin is bundled * Update admin bundler to work with binary bundling * Log detail about the admin interface. Closes #312 * Move bundle script to the build dir * Update to current version of admin * Commit updated API documentation Co-authored-by: Owncast <owncast@owncast.online>pull/329/head
12 changed files with 117 additions and 17 deletions
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash |
||||
# shellcheck disable=SC2059 |
||||
|
||||
set -o errexit |
||||
set -o nounset |
||||
set -o pipefail |
||||
|
||||
INSTALL_TEMP_DIRECTORY="$(mktemp -d)" |
||||
PROJECT_SOURCE_DIR=$(pwd) |
||||
cd $INSTALL_TEMP_DIRECTORY |
||||
|
||||
shutdown () { |
||||
rm -rf "$PROJECT_SOURCE_DIR/admin" |
||||
rm -rf "$INSTALL_TEMP_DIRECTORY" |
||||
} |
||||
trap shutdown INT TERM ABRT EXIT |
||||
|
||||
echo "Cloning owncast admin into $INSTALL_TEMP_DIRECTORY..." |
||||
git clone --depth 1 https://github.com/owncast/owncast-admin 2> /dev/null |
||||
cd owncast-admin |
||||
|
||||
echo "Installing npm modules for the owncast admin..." |
||||
npm --silent install 2> /dev/null |
||||
|
||||
echo "Building owncast admin..." |
||||
rm -rf .next |
||||
(node_modules/.bin/next build && node_modules/.bin/next export) | grep info |
||||
|
||||
echo "Copying admin to project directory..." |
||||
ADMIN_BUILD_DIR=$(pwd) |
||||
cd $PROJECT_SOURCE_DIR |
||||
mkdir -p admin 2> /dev/null |
||||
cd admin |
||||
cp -R ${ADMIN_BUILD_DIR}/out/* . |
||||
|
||||
echo "Bundling admin into owncast codebase..." |
||||
~/go/bin/pkger |
||||
|
||||
shutdown |
||||
echo "Done." |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
package admin |
||||
|
||||
import ( |
||||
"io/ioutil" |
||||
"mime" |
||||
"net/http" |
||||
"path/filepath" |
||||
|
||||
"github.com/markbates/pkger" |
||||
"github.com/owncast/owncast/router/middleware" |
||||
log "github.com/sirupsen/logrus" |
||||
) |
||||
|
||||
// ServeAdmin will return admin web assets
|
||||
func ServeAdmin(w http.ResponseWriter, r *http.Request) { |
||||
// Set a cache control max-age header
|
||||
middleware.SetCachingHeaders(w, r) |
||||
|
||||
path := r.URL.Path |
||||
if path == "/admin" || path == "/admin/" { |
||||
path = "/admin/index.html" |
||||
} |
||||
|
||||
f, err := pkger.Open(path) |
||||
if err != nil { |
||||
log.Warnln(err, path) |
||||
errorHandler(w, r, http.StatusNotFound) |
||||
return |
||||
} |
||||
|
||||
b, err := ioutil.ReadAll(f) |
||||
if err != nil { |
||||
log.Warnln(err) |
||||
return |
||||
} |
||||
|
||||
mimeType := mime.TypeByExtension(filepath.Ext(path)) |
||||
w.Header().Set("Content-Type", mimeType) |
||||
w.Write(b) |
||||
} |
||||
|
||||
func errorHandler(w http.ResponseWriter, r *http.Request, status int) { |
||||
w.WriteHeader(status) |
||||
} |
File diff suppressed because one or more lines are too long
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
PROJECT_SOURCE_DIR=$(pwd) |
||||
mkdir $TMPDIR/admin 2> /dev/null |
||||
cd $TMPDIR/admin |
||||
git clone --depth 1 https://github.com/owncast/owncast-admin 2> /dev/null |
||||
cd owncast-admin |
||||
npm --silent install 2> /dev/null |
||||
(node_modules/.bin/next build && node_modules/.bin/next export) | grep info |
||||
ADMIN_BUILD_DIR=$(pwd) |
||||
cd $PROJECT_SOURCE_DIR |
||||
mkdir webroot/admin 2> /dev/null |
||||
cd webroot/admin |
||||
cp -R ${ADMIN_BUILD_DIR}/out/* . |
||||
rm -rf $TMPDIR/admin |
Loading…
Reference in new issue