Website restoration: Node.js backend, restored design, GitHub sync disabled
- Replaced broken .NET backend with Node.js/Express - Restored original website design with purple gradient hero - Updated homepage and shop pages with Bootstrap 5 responsive design - Disabled GitHub remote sync - all code now stored locally only - Created backup scripts and documentation - All changes saved on Ubuntu server at /var/www/SkyArtShop
This commit is contained in:
84
backend/server.js
Normal file
84
backend/server.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const express = require('express');
|
||||
const session = require('express-session');
|
||||
const pgSession = require('connect-pg-simple')(session);
|
||||
const path = require('path');
|
||||
const { pool } = require('./config/database');
|
||||
require('dotenv').config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', path.join(__dirname, 'views'));
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use('/assets', express.static(path.join(__dirname, '../wwwroot/assets')));
|
||||
app.use('/uploads', express.static(path.join(__dirname, '../wwwroot/uploads')));
|
||||
|
||||
app.use(session({
|
||||
store: new pgSession({
|
||||
pool: pool,
|
||||
tableName: 'session',
|
||||
createTableIfMissing: true
|
||||
}),
|
||||
secret: process.env.SESSION_SECRET || 'skyart-shop-secret-2025',
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: {
|
||||
secure: false,
|
||||
httpOnly: true,
|
||||
maxAge: 24 * 60 * 60 * 1000
|
||||
}
|
||||
}));
|
||||
|
||||
app.use((req, res, next) => {
|
||||
res.locals.session = req.session;
|
||||
res.locals.currentPath = req.path;
|
||||
next();
|
||||
});
|
||||
|
||||
const authRoutes = require('./routes/auth');
|
||||
const adminRoutes = require('./routes/admin');
|
||||
const publicRoutes = require('./routes/public');
|
||||
|
||||
app.use('/admin', authRoutes);
|
||||
app.use('/admin', adminRoutes);
|
||||
app.use('/', publicRoutes);
|
||||
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
database: 'connected'
|
||||
});
|
||||
});
|
||||
|
||||
app.use((req, res) => {
|
||||
res.status(404).render('public/404', {
|
||||
title: '404 - Page Not Found'
|
||||
});
|
||||
});
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
console.error('Error:', err);
|
||||
res.status(500).send('Server error');
|
||||
});
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log('========================================');
|
||||
console.log(' SkyArtShop Backend Server');
|
||||
console.log('========================================');
|
||||
console.log(`🚀 Server running on http://localhost:${PORT}`);
|
||||
console.log(`📦 Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
console.log(`🗄️ Database: PostgreSQL (${process.env.DB_NAME})`);
|
||||
console.log('========================================');
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
console.log('SIGTERM received, closing server...');
|
||||
pool.end(() => {
|
||||
console.log('Database pool closed');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user