d-branch-2 (#18)
* ✨ refactor: streamline sitemap generation and contact form logic * ✨ refactor: update sendEmail function to handle JSON data
This commit is contained in:
@@ -7,7 +7,12 @@ import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const { email, name, message } = await request.json();
|
||||
const body = (await request.json()) as {
|
||||
email: string;
|
||||
name: string;
|
||||
message: string;
|
||||
};
|
||||
const { email, name, message } = body;
|
||||
|
||||
const user = process.env.MY_EMAIL ?? "";
|
||||
const pass = process.env.MY_PASSWORD ?? "";
|
||||
@@ -38,7 +43,7 @@ export async function POST(request: NextRequest) {
|
||||
from: user,
|
||||
to: user, // Ensure this is the correct email address
|
||||
subject: `Message from ${name} (${email})`,
|
||||
text: message + `\n\nSent from ${email}`,
|
||||
text: message + "\n\n" + email,
|
||||
};
|
||||
|
||||
const sendMailPromise = () =>
|
||||
|
||||
@@ -17,40 +17,20 @@ interface SitemapRoute {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "https://dki.one";
|
||||
|
||||
const generateSitemap = async (): Promise<SitemapRoute[]> => {
|
||||
// Static pages
|
||||
const staticRoutes: SitemapRoute[] = [
|
||||
{ url: `${baseUrl}/`, lastModified: new Date().toISOString() },
|
||||
{
|
||||
url: `${baseUrl}/privacy-policy`,
|
||||
lastModified: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/legal-notice`,
|
||||
lastModified: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
try {
|
||||
// Static pages
|
||||
const staticRoutes: SitemapRoute[] = [
|
||||
{ url: `${baseUrl}/`, lastModified: new Date().toISOString() },
|
||||
{
|
||||
url: `${baseUrl}/privacy-policy`,
|
||||
lastModified: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
url: `${baseUrl}/legal-notice`,
|
||||
lastModified: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
|
||||
// Check if running in build environment
|
||||
if (process.env.IS_BUILD) {
|
||||
console.log("Running in build mode - using mock data");
|
||||
const mockProjectsData: ProjectsData = {
|
||||
posts: [
|
||||
{ slug: "project-1" },
|
||||
{ slug: "project-2" },
|
||||
{ slug: "project-3" },
|
||||
],
|
||||
};
|
||||
const projectRoutes: SitemapRoute[] = mockProjectsData.posts.map(
|
||||
(project) => ({
|
||||
url: `${baseUrl}/projects/${project.slug}`,
|
||||
lastModified: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
return [...staticRoutes, ...projectRoutes];
|
||||
}
|
||||
|
||||
// Fetch project data from API
|
||||
console.log("Fetching project data from API...");
|
||||
const response = await fetch(`${baseUrl}/api/fetchAllProjects`, {
|
||||
headers: { "Cache-Control": "no-cache" },
|
||||
@@ -58,13 +38,13 @@ const generateSitemap = async (): Promise<SitemapRoute[]> => {
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Failed to fetch projects: ${response.statusText}`);
|
||||
return staticRoutes; // Return static pages instead of throwing an error
|
||||
return staticRoutes; // Fallback auf statische Seiten
|
||||
}
|
||||
|
||||
const projectsData = (await response.json()) as ProjectsData;
|
||||
console.log("Fetched project data:", projectsData);
|
||||
|
||||
// Generate dynamic routes for projects
|
||||
// Dynamische Projekt-Routen generieren
|
||||
const projectRoutes: SitemapRoute[] = projectsData.posts.map((project) => ({
|
||||
url: `${baseUrl}/projects/${project.slug}`,
|
||||
lastModified: project.updated_at
|
||||
@@ -75,7 +55,7 @@ const generateSitemap = async (): Promise<SitemapRoute[]> => {
|
||||
return [...staticRoutes, ...projectRoutes];
|
||||
} catch (error) {
|
||||
console.error("Failed to generate sitemap:", error);
|
||||
return staticRoutes; // Return static pages in case of failure
|
||||
return staticRoutes; // Fallback nur auf statische Seiten
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user