full upgrade (#31)
* ✨ chore: update CI workflow to include testing and multi-arch build (#29) * ✨ chore: remove unused dependencies from package-lock.json and updated to a better local dev environment (#30) * ✨ test: add unit tests * ✨ test: add unit tests for whole project * ✨ feat: add whatwg-fetch for improved fetch support * ✨ chore: update Node.js version to 22 in workflow * ✨ refactor: update types and improve email handling tests * ✨ refactor: remove unused imports * ✨ fix: normalize image name to lowercase in workflows * ✨ fix: ensure Docker image names are consistently lowercase * ✨ chore: update * ✨ chore: update base URL to use secret variable * ✨ chore: update to login to ghcr * ✨ fix: add missing 'fi' to close if statement in workflow
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import {type NextRequest, NextResponse} from "next/server";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import nodemailer from "nodemailer";
|
||||
import SMTPTransport from "nodemailer/lib/smtp-transport";
|
||||
import Mail from "nodemailer/lib/mailer";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = (await request.json()) as {
|
||||
@@ -12,7 +9,7 @@ export async function POST(request: NextRequest) {
|
||||
name: string;
|
||||
message: string;
|
||||
};
|
||||
const {email, name, message} = body;
|
||||
const { email, name, message } = body;
|
||||
|
||||
const user = process.env.MY_EMAIL ?? "";
|
||||
const pass = process.env.MY_PASSWORD ?? "";
|
||||
@@ -20,8 +17,16 @@ export async function POST(request: NextRequest) {
|
||||
if (!user || !pass) {
|
||||
console.error("Missing email/password environment variables");
|
||||
return NextResponse.json(
|
||||
{error: "Internal server error"},
|
||||
{status: 500},
|
||||
{ error: "Missing EMAIL or PASSWORD" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
if (!email || !name || !message) {
|
||||
console.error("Invalid request body");
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid request body" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,9 +66,9 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
try {
|
||||
await sendMailPromise();
|
||||
return NextResponse.json({message: "Email sent"});
|
||||
return NextResponse.json({ message: "Email sent" });
|
||||
} catch (err) {
|
||||
console.error("Error sending email:", err);
|
||||
return NextResponse.json({error: err}, {status: 500});
|
||||
return NextResponse.json({ error: "Failed to send email" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user