-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (41 loc) · 1.26 KB
/
app.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
const express = require('express');
const pool = require('./dbConfig');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.get('/', (req, res) => {
res.send('Welcome to the homepage'); // Replace with your desired homepage content
});
app.get('/songs/:q', async (req, res) => {
try {
const searchTerm = req.params.q;
const query = 'SELECT * FROM songs WHERE slug = $1';
const { rows } = await pool.query(query, [searchTerm]);
res.status(200).json(rows);
} catch (error) {
res.status(500).send(error.message);
}
});
app.get('/threads/:q', async (req, res) => {
try {
const searchTerm = req.params.q;
const query = 'SELECT * FROM threads WHERE slug = $1';
const { rows } = await pool.query(query, [searchTerm]);
res.status(200).json(rows);
} catch (error) {
res.status(500).send(error.message);
}
});
app.get('/blog/:q', async (req, res) => {
try {
const searchTerm = req.params.q;
const query = 'SELECT * FROM blog WHERE slug = $1';
const { rows } = await pool.query(query, [searchTerm]);
res.status(200).json(rows);
} catch (error) {
res.status(500).send(error.message);
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});