Fix admin route access and backend configuration

- Added /admin redirect to login page in nginx config
- Fixed backend server.js route ordering for proper admin handling
- Updated authentication middleware and routes
- Added user management routes
- Configured PostgreSQL integration
- Updated environment configuration
This commit is contained in:
Local Server
2025-12-13 22:34:11 -06:00
parent 8bb6430a70
commit 703ab57984
253 changed files with 29870 additions and 157 deletions

View File

@@ -1,38 +1,122 @@
const express = require('express');
const { query } = require('../config/database');
const express = require("express");
const { query } = require("../config/database");
const router = express.Router();
router.get('/', async (req, res) => {
// Get all products
router.get("/products", async (req, res) => {
try {
const products = await query(
'SELECT id, name, description, price, imageurl FROM products WHERE isactive = true ORDER BY createdat DESC LIMIT 8'
const result = await query(
"SELECT id, name, description, shortdescription, price, imageurl, images, category, color, stockquantity, isactive, createdat FROM products WHERE isactive = true ORDER BY createdat DESC"
);
const sections = await query(
'SELECT * FROM homepagesections ORDER BY displayorder ASC'
);
res.render('public/home', {
title: 'Welcome - SkyArtShop',
products: products.rows,
sections: sections.rows
res.json({
success: true,
products: result.rows,
});
} catch (error) {
console.error('Home page error:', error);
res.status(500).send('Server error');
console.error("Products API error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
router.get('/shop', async (req, res) => {
// Get featured products
router.get("/products/featured", async (req, res) => {
try {
const products = await query(
'SELECT id, name, description, price, imageurl, category FROM products WHERE isactive = true ORDER BY name ASC'
const limit = parseInt(req.query.limit) || 4;
const result = await query(
"SELECT id, name, description, price, imageurl, images FROM products WHERE isactive = true ORDER BY createdat DESC LIMIT $1",
[limit]
);
res.render('public/shop', {
title: 'Shop - SkyArtShop',
products: products.rows
res.json({
success: true,
products: result.rows,
});
} catch (error) {
console.error('Shop page error:', error);
res.status(500).send('Server error');
console.error("Featured products error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
// Get single product
router.get("/products/:id", async (req, res) => {
try {
const result = await query(
"SELECT * FROM products WHERE id = $1 AND isactive = true",
[req.params.id]
);
if (result.rows.length === 0) {
return res
.status(404)
.json({ success: false, message: "Product not found" });
}
res.json({
success: true,
product: result.rows[0],
});
} catch (error) {
console.error("Product detail error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
// Get site settings
router.get("/settings", async (req, res) => {
try {
const result = await query("SELECT * FROM sitesettings LIMIT 1");
res.json({
success: true,
settings: result.rows[0] || {},
});
} catch (error) {
console.error("Settings error:", error);
res.json({ success: true, settings: {} });
}
});
// Get homepage sections
router.get("/homepage/sections", async (req, res) => {
try {
const result = await query(
"SELECT * FROM homepagesections ORDER BY displayorder ASC"
);
res.json({
success: true,
sections: result.rows,
});
} catch (error) {
console.error("Homepage sections error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
// Get portfolio projects
router.get("/portfolio/projects", async (req, res) => {
try {
const result = await query(
"SELECT id, title, description, imageurl, categoryid, createdat FROM portfolioprojects ORDER BY createdat DESC"
);
res.json({
success: true,
projects: result.rows,
});
} catch (error) {
console.error("Portfolio error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});
// Get blog posts
router.get("/blog/posts", async (req, res) => {
try {
const result = await query(
"SELECT id, title, slug, excerpt, content, imageurl, ispublished, createdat FROM blogposts WHERE ispublished = true ORDER BY createdat DESC"
);
res.json({
success: true,
posts: result.rows,
});
} catch (error) {
console.error("Blog posts error:", error);
res.status(500).json({ success: false, message: "Server error" });
}
});