- 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>
27 lines
872 B
JavaScript
27 lines
872 B
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const mongoose = require('mongoose');
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 5000;
|
|
|
|
app.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE'], allowedHeaders: ['Content-Type', 'Authorization'] }));
|
|
app.use(express.json());
|
|
app.use('/uploads', express.static('uploads'));
|
|
|
|
// MongoDB Connection
|
|
const uri = process.env.MONGO_URI || 'mongodb://localhost:27017/photogallery';
|
|
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
const connection = mongoose.connection;
|
|
connection.once('open', () => {
|
|
console.log("MongoDB database connection established successfully");
|
|
})
|
|
|
|
// API Routes
|
|
const photosRouter = require('./routes/photos');
|
|
app.use('/photos', photosRouter);
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server is running on port: ${port}`);
|
|
});
|