refactor(email): improve code formatting and error handling in email route
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
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";
|
||||
@@ -12,7 +12,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 +20,8 @@ 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: "Internal server error"},
|
||||
{status: 500},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export async function POST(request: NextRequest) {
|
||||
new Promise<string>((resolve, reject) => {
|
||||
transport.sendMail(mailOptions, function (err, info) {
|
||||
if (!err) {
|
||||
console.log("Email sent:", info.response);
|
||||
console.log("Email sent");
|
||||
resolve(info.response);
|
||||
} else {
|
||||
console.error("Error sending email:", err);
|
||||
@@ -61,9 +61,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: err}, {status: 500});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {NextResponse} from "next/server";
|
||||
|
||||
export const runtime = "nodejs"; // Force Node runtime
|
||||
|
||||
const GHOST_API_URL = "http://big-bear-ghost:2368";
|
||||
const GHOST_API_URL = "http://172.21.0.3:2368";
|
||||
const GHOST_API_KEY = process.env.GHOST_API_KEY;
|
||||
|
||||
export async function GET() {
|
||||
@@ -11,15 +11,16 @@ export async function GET() {
|
||||
`${GHOST_API_URL}/ghost/api/content/posts/?key=${GHOST_API_KEY}&limit=all`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch posts: ${response.statusText}`);
|
||||
console.error(`Failed to fetch posts: ${response.statusText}`);
|
||||
return NextResponse.json({});
|
||||
}
|
||||
const posts = await response.json();
|
||||
return NextResponse.json(posts);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch posts from Ghost:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch projects" },
|
||||
{ status: 500 },
|
||||
{error: "Failed to fetch projects"},
|
||||
{status: 500},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ interface ProjectsData {
|
||||
|
||||
export const runtime = "nodejs"; // Force Node runtime
|
||||
|
||||
const GHOST_API_URL = "http://big-bear-ghost:2368";
|
||||
const GHOST_API_URL = "http://172.21.0.3:2368";
|
||||
const GHOST_API_KEY = process.env.GHOST_API_KEY;
|
||||
|
||||
// Funktion, um die XML für die Sitemap zu generieren
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import Link from "next/link";
|
||||
|
||||
interface Project {
|
||||
@@ -27,7 +27,8 @@ export default function Projects() {
|
||||
try {
|
||||
const response = await fetch("/api/fetchAllProjects");
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch projects from Ghost");
|
||||
console.error(`Failed to fetch projects: ${response.statusText}`);
|
||||
return [];
|
||||
}
|
||||
const projectsData = (await response.json()) as ProjectsData;
|
||||
setProjects(projectsData.posts);
|
||||
@@ -42,8 +43,6 @@ export default function Projects() {
|
||||
fetchProjects();
|
||||
}, []);
|
||||
|
||||
console.log(projects.at(0)?.feature_image);
|
||||
|
||||
const numberOfProjects = projects.length;
|
||||
return (
|
||||
<section
|
||||
@@ -57,13 +56,13 @@ export default function Projects() {
|
||||
key={project.id}
|
||||
href={{
|
||||
pathname: `/projects/${project.slug}`,
|
||||
query: { project: JSON.stringify(project) },
|
||||
query: {project: JSON.stringify(project)},
|
||||
}}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<div
|
||||
className={`p-4 border shadow-lg bg-white/45 rounded-2xl animate-fly-in`}
|
||||
style={{ animationDelay: `${index * 0.1}s` }}
|
||||
style={{animationDelay: `${index * 0.1}s`}}
|
||||
>
|
||||
<h3 className="text-2xl font-bold text-gray-800">
|
||||
{project.title}
|
||||
@@ -74,7 +73,7 @@ export default function Projects() {
|
||||
))}
|
||||
<div
|
||||
className={`p-4 border shadow-lg bg-white/45 rounded-2xl animate-fly-in`}
|
||||
style={{ animationDelay: `${(numberOfProjects + 1) * 0.1}s` }}
|
||||
style={{animationDelay: `${(numberOfProjects + 1) * 0.1}s`}}
|
||||
>
|
||||
<h3 className="text-2xl font-bold text-gray-800">More to come</h3>
|
||||
<p className="mt-2 text-gray-500">...</p>
|
||||
|
||||
@@ -59,7 +59,7 @@ const ProjectDetails = () => {
|
||||
try {
|
||||
fetchProjectData(slug);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
setError("Failed to fetch project data");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user