Skip to content

Commit

Permalink
twitter trending topics
Browse files Browse the repository at this point in the history
  • Loading branch information
jongan69 committed Jan 13, 2025
1 parent f53bccd commit 565b1bb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
File renamed without changes.
37 changes: 37 additions & 0 deletions src/pages/api/premium/twitter-trending-topics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { checkApiKey } from '@utils/checkApiKey';
import { getEndpoint } from '@utils/getEndpoint';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}

const apiKey = req.headers['x-api-key'];
if (!apiKey) {
return res.status(401).json({ error: 'API key is required' });
}

try {
const isValid = await checkApiKey(apiKey as string);
if (!isValid) {
return res.status(401).json({ error: 'Invalid API key' });
}
const endpoint = await getEndpoint()
console.log(endpoint)
const response = await fetch(`${endpoint}/api/twitter/trendingTopics`)
const data = await response.json()
console.log(data)
return res.status(200).json(data)

} catch (error) {
console.error('Twitter fetch error:', error);
return res.status(500).json({
success: false,
error: 'Failed to fetch tweets'
});
}
}
2 changes: 1 addition & 1 deletion src/utils/topTickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getTopTickers = async (): Promise<TickerCount[] | null> => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);

const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/premium/twitter`, {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/premium/twitter-trending-tickers`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 565b1bb

Please sign in to comment.