-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (90 loc) · 2.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import express from 'express';
import path from 'path';
import pg from 'pg';
import dotenv from 'dotenv';
import bodyParser from 'body-parser';
import util from 'util';
import { fileURLToPath } from 'url';
import fs from 'fs';
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.use(express.json());
app.set('view engine', 'ejs');
const db = new pg.Client({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
});
db.connect();
const dbQuery = util.promisify(db.query).bind(db);
app.get('/', (req, res) => {
res.render('index');
});
app.get('/about', (req, res) => {
res.render('about');
});
app.get('/contact', (req, res) => {
res.render('contact');
});
app.get('/services', (req, res) => {
res.render('services');
});
app.get('/our_packages', (req, res) => {
res.render('our_packages');
});
app.get('/purchase', (req, res) => {
res.render('purchase');
});
app.get('/teaminfo', (req, res) => {
res.render('teaminfo');
});
app.get('/testimonials', (req, res) => {
res.render('testimonials');
});
app.get('/thankyou', (req, res) => {
res.render('thankyou');
});
app.get('/venu_page', (req, res) => {
res.render('venu_page');
});
app.get('/filter', (req, res) => {
res.render('filter');
});
app.post('/filter', async (req, res) => {
const { type, budget, decoration } = req.body;
try {
const result = await dbQuery(
'SELECT folder_path FROM eventfolders WHERE type = $1 AND budget = $2 AND decoration = $3',
[type, budget, decoration]
);
const folderPath = result.rows[0]?.folder_path;
if (!folderPath) {
return res.render('result', { imagePaths: [] });
}
const absoluteFolderPath = path.join(__dirname, 'public', folderPath);
fs.readdir(absoluteFolderPath, (err, files) => {
if (err) {
console.error(err);
res.send('Error retrieving images');
} else {
const imagePaths = files.map(file => path.join(folderPath, file));
res.render('result', { imagePaths });
}
});
} catch (err) {
console.error(err);
res.send('Error retrieving images');
}
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});