fix api/server.js
This commit is contained in:
parent
71554afae8
commit
ef28e2ea64
|
|
@ -11,9 +11,23 @@ const app = express();
|
|||
const port = process.env.PORT || 3001;
|
||||
|
||||
// 中间件
|
||||
app.use(cors());
|
||||
app.use(cors({
|
||||
origin: '*', // 允许所有来源访问
|
||||
methods: ['GET', 'POST', 'OPTIONS'], // 允许的HTTP方法
|
||||
allowedHeaders: ['Content-Type', 'Authorization'], // 允许的请求头
|
||||
credentials: true // 允许发送凭证
|
||||
}));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// 处理OPTIONS预检请求
|
||||
app.options('*', (req, res) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
res.header('Access-Control-Max-Age', '86400'); // 24小时
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
// 创建Nodemailer传输器
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: process.env.EMAIL_SERVICE || 'smtp', // 邮件服务商,例如:'gmail', 'qq', '163'等
|
||||
|
|
|
|||
Loading…
Reference in New Issue