R-Kentaren commited on
Commit
2422f51
·
verified ·
1 Parent(s): e23c09e

Create src/server.js

Browse files
Files changed (1) hide show
  1. src/server.js +34 -0
src/server.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const cors = require('cors');
3
+ const { searchSoundgasm, getAudioDetails } = require('./soundgasmApi');
4
+
5
+ const app = express();
6
+ const PORT = process.env.PORT || 3000;
7
+
8
+ app.use(cors());
9
+ app.use(express.json());
10
+ app.use(express.static('src/public'));
11
+
12
+ app.get('/api/search', async (req, res) => {
13
+ try {
14
+ const { query } = req.query;
15
+ const results = await searchSoundgasm(query);
16
+ res.json(results);
17
+ } catch (error) {
18
+ res.status(500).json({ error: error.message });
19
+ }
20
+ });
21
+
22
+ app.get('/api/audio/:id', async (req, res) => {
23
+ try {
24
+ const { id } = req.params;
25
+ const audioDetails = await getAudioDetails(id);
26
+ res.json(audioDetails);
27
+ } catch (error) {
28
+ res.status(500).json({ error: error.message });
29
+ }
30
+ });
31
+
32
+ app.listen(PORT, () => {
33
+ console.log(`Server running on port ${PORT}`);
34
+ });