我正在使用nodemailer发送邮件,但是当我第一次重新启动服务器时,它没有给我任何响应,但在此之后工作正常。 请帮我解决这个问题。下面是我的代码: 的 Server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
var fs = require('fs');
var https = require('https');
var options = {
key: fs.readFileSync('app/docs/x.com.key'),
cert: fs.readFileSync('app/docs/x.certificate.crt'),
ca: fs.readFileSync('app/docs/x.bundle.crt')
};
const port = 8000;
var cors = require('cors')
app.use(cors()) // Use this after the variable declaration
app.use(bodyParser.urlencoded({
extended: true
}));
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
app.use(bodyParser.json({limit: '50mb'}));
require('./app/routes')(app, {});
/*
app.listen(port, () => {
console.log('We are live on ' + port);
});*/
https.createServer(options, app, function (req, res) {
res.writeHead(200);
res.end('hello world\n');
}).listen(port);
我正在发送这样的回复:
var new_res = {
"message": "Mail Sent"
}
console.log("sending mail")
res.status(200).send(new_res)