刚刚升级到最新的 FF,我所有的后端开发现在都坏了。
代码示例:
服务器.js
'use strict'
// dependencies
const bodyParser = require('body-parser')
const cors = require('cors')
const express = require('express')
// local definitions
const port = process.env.PORT || 4201
const bugsAPI = require('./bugs.api.js')
const app = express()
// Middleware
app.use(cors())
app.options('*',cors())
var allowCrossDomain = function(req,res,next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE')
res.header('Access-Control-Allow-Headers', 'Content-Type')
next();
}
app.use(allowCrossDomain)
app.use(bodyParser.json())
app.use('/api/bugs', bugsAPI)
app.listen(port, () => console.log(`Server started on port ${port}`))
错误.api.js
const router = require('express').Router()
const mongodb = require('mongodb')
const config = require('./mongo.config.json')
// load current bugList on first request
router.get('/', async (req, res) => {
const bugList = await loadBugsCollection()
res.send(await bugList.find({}).toArray())
})
// Get list of bugs
async function loadBugsCollection() {
const client = await mongodb.MongoClient.connect(
config.mongo_hook,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
)
return client.db(config.db).collection('tickets')
}
module.exports = router
以下解决方案无效:
如何修复“内容安全策略:页面设置阻止在 http://localhost:8080/favicon.ico(“default-src”)加载资源。
https://lollyrock.com/posts/content-security-policy/
如何使用 express/node.js 配置 CSP-headers?
https://github.com/nextcloud/server/issues/12724
如何纠正 nodejs 的问题,反应应用程序未正确加载与内容安全策略相关的内容
即使添加了“unsafe-eval”,CSP 也会阻止对 function() 的调用
https://github.com/helmetjs/helmet
内容安全策略“数据”不适用于 Chrome 28 中的 base64 图像
上周这一切都奏效了。对这种重大变化感到非常沮丧;请帮忙!!