diff --git a/app.js b/app.js index 33dc9d18e3bc790127256958075cbee6500ebe33..2b6a64e5653ff78f242e8b0c7e86ac9210a0aa64 100644 --- a/app.js +++ b/app.js @@ -49,9 +49,13 @@ pool.getConnection() }); // ตัวอย่าง route ทดสอบ -const indexController = require('./controllers/indexController'); - -app.get('/', indexController.getProducts); +app.get('/', (req, res) => { + if (req.session.user) { + res.sendFile(path.join(__dirname, 'public', 'index.ejs')); + } else { + + } +}); // Start the server const port = process.env.PORT || 3000; diff --git a/controllers/indexController.js b/controllers/indexController.js deleted file mode 100644 index 932af7d1986a687d306782f9f20f835d1756d2b2..0000000000000000000000000000000000000000 --- a/controllers/indexController.js +++ /dev/null @@ -1,30 +0,0 @@ -const pool = require('../db'); - -exports.getProducts = async (req, res) => { - try { - const [rows] = await pool.query('SELECT * FROM products'); - res.render('index', { products: rows }); - } catch (err) { - res.status(500).send('Database error: ' + err.message); - } - }; - - exports.getProductDetail = async (req, res) => { - const productId = req.params.id; - try { - const [rows] = await pool.query(` - SELECT p.*, u.email AS owner - FROM products p - LEFT JOIN users u ON p.owner = u.email - WHERE p.product_id = ?`, [productId]); - - if (rows.length === 0) { - return res.status(404).send('ไม่พบสินค้านี้'); - } - - res.render('product', { product: rows[0], currentUserEmail: req.session.userIdEmail || '' }); - } catch (err) { - res.status(500).send('Database error: ' + err.message); - } - }; - \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index a4454031135b6169dd50020f1ad95df3cabb6377..c3c6d486697f63c43c731bc2458056b7645b26f1 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -116,4 +116,4 @@ displayUsername(); // Display user info when page loads </script> </body> -</html> \ No newline at end of file +</html>