(req: NextApiRequest, res: NextApiResponse)
| 2 | import { init } from '@amplitude/analytics-browser'; |
| 3 | |
| 4 | export default function handler(req: NextApiRequest, res: NextApiResponse) { |
| 5 | if (req.method === 'POST') { |
| 6 | try { |
| 7 | const apiKey = process.env.AMPLITUDE_API_KEY; |
| 8 | if (!apiKey) { |
| 9 | return res.status(500).json({ error: 'Amplitude API key not defined' }); |
| 10 | } |
| 11 | |
| 12 | //init(apiKey); // Initialize Amplitude |
| 13 | res.status(200).json({ message: 'Amplitude initialized successfully' }); |
| 14 | |
| 15 | // Log initialization in development mode |
| 16 | if (process.env.NODE_ENV === 'development') { |
| 17 | console.log('Amplitude initialized'); |
| 18 | } |
| 19 | } catch (error) { |
| 20 | console.error('Error initializing Amplitude:', error); |
| 21 | res.status(500).json({ error: 'Failed to initialize Amplitude' }); |
| 22 | } |
| 23 | } else { |
| 24 | // Handle any other HTTP method |
| 25 | res.setHeader('Allow', ['POST']); |
| 26 | res.status(405).end(`Method ${req.method} Not Allowed`); |
| 27 | } |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected