Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8404125ff0 | |||
| 61ad2d61c1 | |||
| 9fd6b44487 | |||
| 9fe10bcce2 | |||
| f2abb40987 | |||
| 3697344cd0 |
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "^3.850.0",
|
||||
"@aws-sdk/lib-storage": "^3.850.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "picpeak-backend",
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"description": "Backend for PicPeak event photo sharing platform",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -12,6 +12,7 @@ logger.info('Server starting up', {
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
const helmet = require('helmet');
|
||||
const cors = require('cors');
|
||||
@@ -219,6 +220,22 @@ app.use('/api/public', require('./src/routes/publicCMS'));
|
||||
app.use('/api/images', require('./src/routes/protectedImages'));
|
||||
app.use('/api/secure-images', secureImagesRoutes);
|
||||
|
||||
// Optional: Serve built frontend (native installs)
|
||||
try {
|
||||
const serveFrontend = process.env.SERVE_FRONTEND === 'true';
|
||||
const frontendDir = process.env.FRONTEND_DIR || path.join(__dirname, '../frontend/dist');
|
||||
if (serveFrontend && fs.existsSync(frontendDir)) {
|
||||
logger.info(`Serving frontend from ${frontendDir}`);
|
||||
app.use(express.static(frontendDir));
|
||||
// SPA fallback for non-API routes
|
||||
app.get([ '/', '/admin', '/admin/*', '/gallery/*' ], (req, res) => {
|
||||
res.sendFile(path.join(frontendDir, 'index.html'));
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn('Failed to enable frontend static serving', { error: e.message });
|
||||
}
|
||||
|
||||
// Error handling middleware
|
||||
app.use((err, req, res, next) => {
|
||||
console.error('EXPRESS ERROR HANDLER:', err);
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "picpeak-frontend",
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "picpeak-frontend",
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.0.0",
|
||||
"@tiptap/extension-character-count": "^2.26.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "picpeak-frontend",
|
||||
"private": true,
|
||||
"version": "1.0.114",
|
||||
"version": "1.0.117",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
+48
-7
@@ -580,10 +580,15 @@ setup_native_installation() {
|
||||
log_step "Downloading PicPeak..."
|
||||
if [[ -d "$NATIVE_APP_DIR/app/.git" ]]; then
|
||||
cd "$NATIVE_APP_DIR/app"
|
||||
run_as_user "git pull --ff-only" || {
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app"
|
||||
run_as_user "git pull --ff-only"
|
||||
}
|
||||
# Ensure correct remote and update even if history was rewritten
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app" || true
|
||||
run_as_user "git remote set-url origin $REPO_URL" || true
|
||||
run_as_user "git fetch --all --prune" || true
|
||||
# Prefer checking out remote main and hard resetting to avoid merge prompts
|
||||
if ! run_as_user "git checkout -B main origin/main"; then
|
||||
run_as_user "git checkout main" || true
|
||||
run_as_user "git reset --hard origin/main"
|
||||
fi
|
||||
else
|
||||
run_as_user "git clone $REPO_URL $NATIVE_APP_DIR/app" || {
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app"
|
||||
@@ -597,9 +602,19 @@ setup_native_installation() {
|
||||
# Install backend production dependencies
|
||||
cd "$NATIVE_APP_DIR/app/backend"
|
||||
npm install --production
|
||||
|
||||
# Ensure SQLite data directory exists for native installs
|
||||
mkdir -p "$NATIVE_APP_DIR/app/backend/data"
|
||||
|
||||
# Build frontend for native serving
|
||||
log_step "Building frontend..."
|
||||
if [[ -d "$NATIVE_APP_DIR/app/frontend" ]]; then
|
||||
cd "$NATIVE_APP_DIR/app/frontend"
|
||||
# Try ci (faster/clean) then fallback to install
|
||||
run_as_user "npm ci --include=dev" || run_as_user "npm install"
|
||||
run_as_user "npm run build"
|
||||
else
|
||||
log_warn "Frontend directory not found; admin UI will not be served by backend"
|
||||
fi
|
||||
|
||||
# Generate secrets
|
||||
local jwt_secret=$(generate_jwt_secret)
|
||||
@@ -649,6 +664,10 @@ DEFAULT_EXPIRY_DAYS=30
|
||||
# Logging
|
||||
LOG_DIR=$NATIVE_APP_DIR/logs
|
||||
LOG_LEVEL=info
|
||||
|
||||
# Frontend serving (native installs)
|
||||
SERVE_FRONTEND=true
|
||||
FRONTEND_DIR=$NATIVE_APP_DIR/app/frontend/dist
|
||||
EOF
|
||||
|
||||
# Set permissions
|
||||
@@ -976,7 +995,13 @@ update_native_installation() {
|
||||
|
||||
# Pull latest code
|
||||
cd "$NATIVE_APP_DIR/app"
|
||||
run_as_user "git pull --ff-only" || run_as_user "git pull"
|
||||
run_as_user "git config --global --add safe.directory $NATIVE_APP_DIR/app" || true
|
||||
run_as_user "git remote set-url origin $REPO_URL" || true
|
||||
run_as_user "git fetch --all --prune"
|
||||
if ! run_as_user "git checkout -B main origin/main"; then
|
||||
run_as_user "git checkout main" || true
|
||||
run_as_user "git reset --hard origin/main"
|
||||
fi
|
||||
|
||||
# Update backend dependencies
|
||||
cd "$NATIVE_APP_DIR/app/backend"
|
||||
@@ -984,9 +1009,25 @@ update_native_installation() {
|
||||
|
||||
# Run migrations
|
||||
run_as_user "npm run migrate"
|
||||
|
||||
# Rebuild frontend (ensure admin UI for native installs)
|
||||
if [[ -d "$NATIVE_APP_DIR/app/frontend" ]]; then
|
||||
log_step "Rebuilding frontend..."
|
||||
cd "$NATIVE_APP_DIR/app/frontend"
|
||||
run_as_user "npm ci --include=dev" || run_as_user "npm install"
|
||||
run_as_user "npm run build"
|
||||
fi
|
||||
|
||||
# Ensure env has frontend serving flags
|
||||
if ! grep -q '^SERVE_FRONTEND=' "$NATIVE_APP_DIR/app/backend/.env"; then
|
||||
echo "SERVE_FRONTEND=true" >> "$NATIVE_APP_DIR/app/backend/.env"
|
||||
fi
|
||||
if ! grep -q '^FRONTEND_DIR=' "$NATIVE_APP_DIR/app/backend/.env"; then
|
||||
echo "FRONTEND_DIR=$NATIVE_APP_DIR/app/frontend/dist" >> "$NATIVE_APP_DIR/app/backend/.env"
|
||||
fi
|
||||
|
||||
# Restart services
|
||||
systemctl start picpeak-backend picpeak-workers
|
||||
systemctl restart picpeak-backend picpeak-workers
|
||||
|
||||
log_success "Native installation updated successfully!"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user