mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-05-26 18:44:44 +00:00
fix(bentopdf): replace http-server with nginx for COOP/COEP headers
Word/Excel/PowerPoint to PDF conversion uses LibreOffice WASM which requires SharedArrayBuffer. SharedArrayBuffer only works when the server sends Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp headers. The previous http-server setup did not send these headers, causing WASM initialization to time out for office-format conversions. Fix: replace http-server with nginx and configure COOP/COEP headers in the nginx site config, matching the upstream Docker image's nginx.conf. Also adds a one-time migration path in update_script for existing installs running the old http-server service.
This commit is contained in:
+41
-5
@@ -42,7 +42,6 @@ function update_script() {
|
|||||||
msg_info "Updating BentoPDF"
|
msg_info "Updating BentoPDF"
|
||||||
cd /opt/bentopdf
|
cd /opt/bentopdf
|
||||||
$STD npm ci --no-audit --no-fund
|
$STD npm ci --no-audit --no-fund
|
||||||
$STD npm install http-server -g
|
|
||||||
if [[ -f /opt/production.env ]]; then
|
if [[ -f /opt/production.env ]]; then
|
||||||
mv /opt/production.env ./.env.production
|
mv /opt/production.env ./.env.production
|
||||||
else
|
else
|
||||||
@@ -55,10 +54,47 @@ function update_script() {
|
|||||||
msg_ok "Updated BentoPDF"
|
msg_ok "Updated BentoPDF"
|
||||||
|
|
||||||
msg_info "Starting Service"
|
msg_info "Starting Service"
|
||||||
if grep -q '8080' /etc/systemd/system/bentopdf.service; then
|
if ! command -v nginx &>/dev/null; then
|
||||||
sed -i -e 's|/bentopdf|/bentopdf/dist|' \
|
ensure_dependencies nginx
|
||||||
-e 's|npx.*|npx http-server -g -b -d false -r --no-dotfiles|' \
|
cat <<'EOF' >/etc/nginx/sites-available/bentopdf
|
||||||
/etc/systemd/system/bentopdf.service
|
server {
|
||||||
|
listen 8080;
|
||||||
|
server_name _;
|
||||||
|
root /opt/bentopdf/dist;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# Required for LibreOffice WASM (Word/Excel/PowerPoint to PDF via SharedArrayBuffer)
|
||||||
|
add_header Cross-Origin-Opener-Policy "same-origin" always;
|
||||||
|
add_header Cross-Origin-Embedder-Policy "require-corp" always;
|
||||||
|
add_header Cross-Origin-Resource-Policy "cross-origin" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
|
||||||
|
gzip_static on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ $uri.html =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 404 /404.html;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
ln -sf /etc/nginx/sites-available/bentopdf /etc/nginx/sites-enabled/bentopdf
|
||||||
|
cat <<'EOF' >/etc/systemd/system/bentopdf.service
|
||||||
|
[Unit]
|
||||||
|
Description=BentoPDF Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/sbin/nginx -g "daemon off;"
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
fi
|
fi
|
||||||
systemctl start bentopdf
|
systemctl start bentopdf
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ fetch_and_deploy_gh_release "bentopdf" "alam00000/bentopdf" "tarball" "latest" "
|
|||||||
msg_info "Setup BentoPDF"
|
msg_info "Setup BentoPDF"
|
||||||
cd /opt/bentopdf
|
cd /opt/bentopdf
|
||||||
$STD npm ci --no-audit --no-fund
|
$STD npm ci --no-audit --no-fund
|
||||||
$STD npm install http-server -g
|
ensure_dependencies nginx
|
||||||
cp ./.env.example ./.env.production
|
cp ./.env.example ./.env.production
|
||||||
export NODE_OPTIONS="--max-old-space-size=3072"
|
export NODE_OPTIONS="--max-old-space-size=3072"
|
||||||
export SIMPLE_MODE=true
|
export SIMPLE_MODE=true
|
||||||
@@ -28,17 +28,41 @@ $STD npm run build:all
|
|||||||
msg_ok "Setup BentoPDF"
|
msg_ok "Setup BentoPDF"
|
||||||
|
|
||||||
msg_info "Creating Service"
|
msg_info "Creating Service"
|
||||||
cat <<EOF >/etc/systemd/system/bentopdf.service
|
cat <<'EOF' >/etc/nginx/sites-available/bentopdf
|
||||||
|
server {
|
||||||
|
listen 8080;
|
||||||
|
server_name _;
|
||||||
|
root /opt/bentopdf/dist;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# Required for LibreOffice WASM (Word/Excel/PowerPoint to PDF via SharedArrayBuffer)
|
||||||
|
add_header Cross-Origin-Opener-Policy "same-origin" always;
|
||||||
|
add_header Cross-Origin-Embedder-Policy "require-corp" always;
|
||||||
|
add_header Cross-Origin-Resource-Policy "cross-origin" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
|
||||||
|
gzip_static on;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ $uri.html =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_page 404 /404.html;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
rm -f /etc/nginx/sites-enabled/default
|
||||||
|
ln -sf /etc/nginx/sites-available/bentopdf /etc/nginx/sites-enabled/bentopdf
|
||||||
|
cat <<'EOF' >/etc/systemd/system/bentopdf.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=BentoPDF Service
|
Description=BentoPDF Service
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/opt/bentopdf/dist
|
ExecStart=/usr/sbin/nginx -g "daemon off;"
|
||||||
ExecStart=/usr/bin/npx http-server -g -b -d false -r --no-dotfiles
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
Reference in New Issue
Block a user