8 changed files with 8760 additions and 4653 deletions
-
3.gitignore
-
27dist/index.html
-
22package.json
-
29src-server/email.ts
-
59src-server/server.ts
-
27src/html/index.html
-
12tsconfig.json
-
13232yarn.lock
@ -0,0 +1,29 @@ |
|||||
|
import nodemailer from "nodemailer"; |
||||
|
import dotenv from "dotenv"; |
||||
|
|
||||
|
dotenv.config(); |
||||
|
|
||||
|
export const sendEmail = async (to: string, subject: string, text: string) => { |
||||
|
const transporter = nodemailer.createTransport({ |
||||
|
service: "gmail", |
||||
|
auth: { |
||||
|
user: "wheeparamsoft.mail", |
||||
|
pass: "gjyr slpt zwhv whvf", |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
const mailOptions = { |
||||
|
from: "support@wheeparam.com", |
||||
|
to, |
||||
|
subject, |
||||
|
text, |
||||
|
}; |
||||
|
|
||||
|
try { |
||||
|
await transporter.sendMail(mailOptions); |
||||
|
console.log(`Email sent to ${to}`); |
||||
|
} catch (error) { |
||||
|
console.error("Email sending error:", error); |
||||
|
throw error; |
||||
|
} |
||||
|
}; |
@ -0,0 +1,59 @@ |
|||||
|
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) => { |
||||
|
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} 에서 실행 중입니다.`); |
||||
|
}); |
@ -0,0 +1,12 @@ |
|||||
|
{ |
||||
|
"compilerOptions": { |
||||
|
"target": "ES2020", |
||||
|
"module": "CommonJS", |
||||
|
"outDir": "./dist-server", |
||||
|
"rootDir": "./src-server", |
||||
|
"strict": true, |
||||
|
"esModuleInterop": true |
||||
|
}, |
||||
|
"include": ["src-server/**/*"], |
||||
|
"exclude": ["node_modules"] |
||||
|
} |
13232
yarn.lock
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Reference in new issue
xxxxxxxxxx