fixed proxy for backend and route api calls, do not use node environment property when in production

This commit is contained in:
Jacob Delgado 2024-09-01 00:26:02 -07:00
parent 5f0e56abec
commit 26b2367c8d
9 changed files with 29 additions and 20 deletions

View File

@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = {}; const nextConfig = {
async rewrites() {
return [
{
source: '/backend/:path*',
destination: `http://192.168.50.107:5580/:path*`,
},
]
},
};
export default nextConfig; export default nextConfig;

View File

@ -2,10 +2,11 @@
"name": "kevos-attire", "name": "kevos-attire",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"proxy": "http://192.168.50.107:5580/",
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start -p 3003",
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {

View File

@ -1,5 +1,6 @@
"use server"
import { sendEmails } from "@/lib/mail.utils" import { sendEmails } from "@/lib/mail.utils"
import { NextRequest } from "next/server" import { NextRequest, NextResponse } from "next/server"
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
const sender = { const sender = {
@ -18,14 +19,18 @@ export async function POST(request: NextRequest) {
const result = await sendEmails({ const result = await sendEmails({
sender, sender,
recipients, recipients,
subject: "New Email!", subject: "New Order!",
message: `New order from ${clientEmail}` message: `New order from ${clientEmail.senderEmail}`
}) })
return Response.json({ return NextResponse.json({
accepted: result.accepted, accepted: result.accepted,
}) })
} catch (error){ } catch (error){
return Response.json({message: 'Unable to send email at this time.'}, {status: 500}) return NextResponse.json({message: 'Unable to send email at this time.'}, {status: 500})
} }
} }
export async function GET(req: NextRequest){
return NextResponse.json({message: 'Hello'})
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

BIN
frontend/src/app/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -37,24 +37,21 @@ export default function Home() {
// Send new order email to self // Send new order email to self
const clientEmail = formData.get('senderEmail') as string const clientEmail = formData.get('senderEmail') as string
console.log(JSON.stringify({"senderEmail":clientEmail}))
await fetch("/api/emails", { await fetch("/api/emails", {
method: "POST", method: "POST",
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
}, },
body: JSON.stringify(clientEmail), body: JSON.stringify({"senderEmail":clientEmail}),
}) })
// .then((response) => response.json())
// .then((data) => {
// console.log(data);
// })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
}); });
// const response = await fetch("http://192.168.50.107:5580/new-order", { const response = await fetch("/backend/new-order", {
const response = await fetch("http://localhost:5080/new-order", { // const response = await fetch("http://localhost:5080/new-order", {
method: "POST", method: "POST",
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
@ -62,9 +59,6 @@ export default function Home() {
body: JSON.stringify(payload), body: JSON.stringify(payload),
}) })
.then((response) => response.json()) .then((response) => response.json())
// .then((data) => {
// console.log(data);
// })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
}); });
@ -74,7 +68,7 @@ export default function Home() {
emails: "", emails: "",
orders: "", orders: "",
}); });
// alert("Order Placed! Please check your email.") alert("Order Placed! Please check your email.")
} }
return ( return (

View File

@ -1,12 +1,12 @@
"use server"
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import Mail from "nodemailer/lib/mailer"; import Mail from "nodemailer/lib/mailer";
import SMTPTransport from "nodemailer/lib/smtp-transport"; import SMTPTransport from "nodemailer/lib/smtp-transport";
import * as React from 'react';
const transport = nodemailer.createTransport({ const transport = nodemailer.createTransport({
host: process.env.MAIL_HOST, host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT, port: process.env.MAIL_PORT,
secure: process.env.NODE_ENV !== 'development', //true // secure: process.env.NODE_ENV !== 'development', //true // DO NOT USE FOR PRODUCTION BUILD
auth: { auth: {
user: process.env.MAIL_USER, user: process.env.MAIL_USER,
pass: process.env.MAIL_PASSWORD pass: process.env.MAIL_PASSWORD