mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import axios from 'axios';
|
|
|
|
export default async function handler(req, res) {
|
|
try {
|
|
const response = await axios.post('https://stacker.news/api/graphql', {
|
|
query: `
|
|
query RecentDevItemsWithComments {
|
|
items(
|
|
sub: "devs",
|
|
sort: "recent"
|
|
) {
|
|
items {
|
|
id
|
|
title
|
|
url
|
|
createdAt
|
|
user {
|
|
name
|
|
}
|
|
sats
|
|
comments {
|
|
id
|
|
text
|
|
createdAt
|
|
user {
|
|
name
|
|
}
|
|
sats
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
}, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
}
|
|
});
|
|
|
|
res.status(200).json(response.data);
|
|
} catch (error) {
|
|
console.error('Error fetching from Stacker News:', error.response ? error.response.data : error.message);
|
|
res.status(500).json({ error: 'An error occurred while fetching data' });
|
|
}
|
|
}
|