-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (31 loc) · 1.11 KB
/
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
32
33
34
35
36
37
38
require('dotenv').config();
const express = require('express');
const axios = require('axios');
const cors = require('cors');
const app = express();
app.use(cors());
app.get('/horoscope/:sign', async (req, res) => {
try {
const { sign } = req.params;
const response = await axios.get(`https://horoscope-app-api.vercel.app/api/v1/get-horoscope/daily?sign=${sign}&day=TODAY`);
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.toString() });
}
});
app.get('/weather/:location', async (req, res) => {
const apiKey = process.env.WEATHER_API;
try {
const { location } = req.params;
const response = await axios.get(`https://api.weatherapi.com/v1/forecast.json?key=${apiKey}&q=${location}&days=1&aqi=no&alerts=no`);
res.json(response.data);
} catch (error) {
console.log(error)
res.status(500).json({ error: error.toString() });
}
})
app.get('/', (req, res) => {
res.send('Server is running. This is the root URL')
})
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server running on port ${port}`));