You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
import express, {Request, Response} from "express";
|
|
import path from "path";
|
|
import dotenv from "dotenv";
|
|
import { sendEmail } from "./email";
|
|
|
|
dotenv.config();
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3070;
|
|
|
|
// 정적 파일 서빙
|
|
app.use("/", express.static(path.join(__dirname, "../dist")));
|
|
app.use("/assets", express.static(path.join(__dirname, "../dist")));
|
|
|
|
// JSON 요청을 받기 위한 미들웨어
|
|
app.use(express.json()); // application/json 파싱
|
|
app.use(express.urlencoded({ extended: true })); // application/x-www-form-urlencoded 파싱
|
|
|
|
|
|
// /request API
|
|
app.post("/request", async (req: Request, res: Response) => {
|
|
|
|
console.log(req)
|
|
const {
|
|
type = "",
|
|
phone = "",
|
|
company_name = "",
|
|
manager_name = "",
|
|
email,
|
|
budget_range,
|
|
contents
|
|
} = await req.body;
|
|
|
|
|
|
if (!email || !contents) {
|
|
res.status(400).json({ error: "모든 필드가 필요합니다." });
|
|
return
|
|
}
|
|
|
|
try {
|
|
await sendEmail(email, `${type} 문의`, `
|
|
문의 유형: ${type}
|
|
전화번호: ${phone}
|
|
회사명: ${company_name}
|
|
담당자명: ${manager_name}
|
|
이메일: ${email}
|
|
예산 범위: ${budget_range}
|
|
문의 내용: ${contents}
|
|
`);
|
|
res.json({ message: "이메일이 성공적으로 전송되었습니다." });
|
|
return
|
|
} catch (error) {
|
|
console.error("이메일 전송 오류:", error);
|
|
res.status(500).json({ error: "이메일 전송에 실패했습니다." });
|
|
return
|
|
}
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`서버가 http://localhost:${PORT} 에서 실행 중입니다.`);
|
|
});
|