在Heroku上部署Nodejs服务器并在浏览器中打开Herroku服务器后,他会遇到问题

时间:2020-03-19 12:23:10

标签: node.js heroku

拒绝加载图像'https://send-mail-backend.herokuapp.com/favicon.ico',因为它违反了以下内容安全策略指令:“ default-src'none'”。请注意,未明确设置“ img-src”,因此将“ default-src”用作备用。

这是我用于服务器的package.json:

{

“名称”:“邮件”,

“版本”:“ 1.0.0”,

“说明”:“”,

“主要”:“ server.js”,

“脚本”:{

"start": "nodemon server.js"

},

“关键字”:[],

“作者”:“”,

“许可证”:“ ISC”,

“ devDependencies”:{

"nodemon": "^2.0.2"

},

“依赖项”:{

"body-parser": "^1.19.0",

"cors": "^2.8.5",

"express": "^4.17.1",

"nodemailer": "^6.4.5",

"nodemailer-mailgun-transport": "^2.0.0"

}

}

这是Server.js:

const express = require('express');

const sendMail = require('./ mail');

const cors = require('cors');

const app = express();

常量端口= process.env.PORT;

app.use(express.urlencoded({ 扩展:假 }));

app.use(cors())

app.use(express.json());

app.post('/ email',(req,res)=> {

console.log('Data :', req.body);


const { subject, email, text } = req.body;

sendMail(email, subject, text, (err, data) => {

    if (err) {

        res.status(500).json({ message: 'Internal Error' });

    } else {

        res.json({ message: 'email sent!' });
    }
});

});

app.listen(PORT || 3000,()=> {

console.log('Server is starting on port: ', PORT);

});

0 个答案:

没有答案