-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (22 loc) · 858 Bytes
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const { getChordFunctionFromName } = require('./chordFunctions');
const app = express();
const PORT = 8000;
app.use(bodyParser.json()); // Middleware to parse JSON bodies
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.get('/API', (req, res) => {
const { keyCenter, chordRoot, quality } = req.query;
console.log(`Received request with keyCenter: ${keyCenter}, chordRoot: ${chordRoot}, quality: ${quality}`);
try {
const chordFunction = getChordFunctionFromName(keyCenter, chordRoot, quality);
res.json({ chordFunction });
} catch (error) {
res.status(400).json({ error: error.message });
}
});
app.listen(process.env.PORT || PORT, () => {
console.log(`Server listening on ${PORT}`);
});