File size: 1,573 Bytes
5fa914f
157ec4e
1402ec2
5fa914f
 
 
 
 
 
494cdab
 
168994a
 
 
 
 
 
5fa914f
 
 
494cdab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fa914f
1402ec2
5fa914f
 
 
 
 
 
 
 
 
 
 
 
 
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
import express from 'express';
import { GempaBumi } from '../lib/scrapper.js';
import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
const GempaRoutes = express.Router();

/**
 * @swagger
 * /api/v1/gempa-bumi:
 *   get:
 *     summary: Get random earthquake data
 *     parameters:
 *       - in: header
 *         name: x-api-key
 *         required: true
 *         description: API key for authentication
 *         schema:
 *           type: string
 *     responses:
 *       200:
 *         description: Success
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: string
 *                       magnitude:
 *                         type: number
 *                       location:
 *                         type: string
 *                       time:
 *                         type: string
 *                         format: date-time
 */
GempaRoutes.get('/api/v1/gempa-bumi', authenticateApiKey, apiLimiter, async (req, res) => {
    try {
        const result = await GempaBumi();
        if (result) {
            res.json({ result });
        } else {
            res.status(404).json({ error: "No result found." });
        }
    } catch (error) {
        res.status(500).json({ error: error.message });
    }
});

export { GempaRoutes };