fix: resolve gallery CORS failure and simplify API routing
- gallery backend: replace origin whitelist with wildcard CORS — NPMplus was stripping the Allow-Origin header; wildcard passes through reliably and is appropriate for a public photo gallery - gallery.js: hardcode photobackend.beachpartyballoons.com as the API base (NPMplus already routes this subdomain) and remove dead port fallbacks - nginx.conf: add /photos and /uploads proxy routes to gallery-backend (kept for direct-nginx access; NPMplus handles external traffic) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4a135a7919
commit
92cf44e5f5
@ -80,10 +80,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const apiBaseCandidates = (() => {
|
||||
const hints = [
|
||||
window.GALLERY_API_URL || '',
|
||||
'', // same-origin via nginx proxy
|
||||
'https://photobackend.beachpartyballoons.com',
|
||||
];
|
||||
// Remove duplicates/empties — empty string means same-origin (/photos, /uploads)
|
||||
return [...new Set(hints)];
|
||||
return [...new Set(hints.filter(Boolean))];
|
||||
})();
|
||||
|
||||
let activeApiBase = '';
|
||||
@ -215,7 +214,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const resolveUrl = (p) => {
|
||||
if (typeof p !== 'string') return '';
|
||||
if (p.startsWith('http') || p.startsWith('assets') || p.startsWith('/assets') || p.startsWith('../assets')) return p;
|
||||
const base = activeApiBase || '';
|
||||
const base = activeApiBase || 'https://photobackend.beachpartyballoons.com';
|
||||
const path = p.startsWith('/') ? p.slice(1) : p;
|
||||
return `${base.replace(/\/$/, '')}/${path}`;
|
||||
};
|
||||
|
||||
@ -5,30 +5,7 @@ const mongoose = require('mongoose');
|
||||
const app = express();
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
const whitelist = [
|
||||
'https://preview.beachpartyballoons.com',
|
||||
'https://beachpartyballoons.com',
|
||||
'https://www.beachpartyballoons.com',
|
||||
'https://photobackend.beachpartyballoons.com', // Dedicated backend hostname
|
||||
'http://localhost:3052',
|
||||
'http://127.0.0.1:3052',
|
||||
'http://localhost:3050',
|
||||
'http://127.0.0.1:3050',
|
||||
'http://localhost:8080' // Common local dev port
|
||||
];
|
||||
const corsOptions = {
|
||||
origin: function (origin, callback) {
|
||||
if (whitelist.indexOf(origin) !== -1 || !origin) { // !origin allows same-origin and server-to-server
|
||||
callback(null, true);
|
||||
} else {
|
||||
callback(new Error('Not allowed by CORS'));
|
||||
}
|
||||
},
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization']
|
||||
};
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
app.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE'], allowedHeaders: ['Content-Type', 'Authorization'] }));
|
||||
app.use(express.json());
|
||||
app.use('/uploads', express.static('uploads'));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user