Any file named route.js in the /app/api folder is an API endpoint. Use the helper /libs/api.js (axios instance with interceptors) to simplify API calls:
2. In the backend, we get the session and we can use it to retrieve the user from the database. You have to configure the database first. The API file should look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { sendEmail } from '@/utils/mailgun';
export default async function handler(req: any, res: any) {
if (req.method === 'POST') {
const { to, subject, text } = req.body;
try {
const result = await sendEmail(to, subject, text);
res.status(200).json({ success: true, result });
} catch (error) {
res.status(500).json({ success: false, error: (error as Error).message });
}
} else {
res.status(405).json({ message: 'Method Not Allowed' });
}
}
Any file named route.js in the /app/api folder is an API endpoint. Use the helper /libs/api.js (axios instance with interceptors) to simplify API calls:
2. In the backend, we get the session and we can use it to retrieve the user from the database. You have to configure the database first. The API file should look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { sendEmail } from '@/utils/mailgun';
export default async function handler(req: any, res: any) {
if (req.method === 'POST') {
const { to, subject, text } = req.body;
try {
const result = await sendEmail(to, subject, text);
res.status(200).json({ success: true, result });
} catch (error) {
res.status(500).json({ success: false, error: (error as Error).message });
}
} else {
res.status(405).json({ message: 'Method Not Allowed' });
}
}