HerzaJ commited on
Commit
44e80ae
·
verified ·
1 Parent(s): 7f8abdd

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +34 -2
index.js CHANGED
@@ -1,6 +1,12 @@
 
1
  const { chromium } = require('playwright');
2
 
3
- async function lyrics(query) {
 
 
 
 
 
4
  let browser;
5
  try {
6
  browser = await chromium.launch({
@@ -101,4 +107,30 @@ async function lyrics(query) {
101
  }
102
  }
103
 
104
- module.exports = lyrics;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
  const { chromium } = require('playwright');
3
 
4
+ const app = express();
5
+ const PORT = process.env.PORT || 7860;
6
+
7
+ app.use(express.json());
8
+
9
+ async function getLyrics(query) {
10
  let browser;
11
  try {
12
  browser = await chromium.launch({
 
107
  }
108
  }
109
 
110
+ app.get('/', (req, res) => {
111
+ res.json({
112
+ status: 'online',
113
+ message: 'AZLyrics API is running',
114
+ endpoints: {
115
+ lyrics: '/lyrics?q=song_name'
116
+ }
117
+ });
118
+ });
119
+
120
+ app.get('/lyrics', async (req, res) => {
121
+ const query = req.query.q;
122
+
123
+ if (!query) {
124
+ return res.status(400).json({
125
+ error: 'Parameter q diperlukan',
126
+ example: '/lyrics?q=stecu'
127
+ });
128
+ }
129
+
130
+ const result = await getLyrics(query);
131
+ res.json(result);
132
+ });
133
+
134
+ app.listen(PORT, '0.0.0.0', () => {
135
+ console.log(`Server running on port ${PORT}`);
136
+ });