【发布时间】:2020-07-03 04:23:37
【问题描述】:
所以我使用React-S3 将文件从我的反应应用程序上传到 S3 存储桶。我正在使用代理服务器,但仍然给我以下错误
Access to fetch at 'https://atlantic-files.s3.amazonaws.com/' from origin 'http://localhost:5000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
这是我的服务器
const express = require('express');
const bodyParser = require('body-parser')
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Methods', "GET,PUT,POST,DELETE");
res.header('Access-Control-Allow-Methods', "Content-Type");
next();
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build/index.html'), function (err) {
if (err) {
res.status(500).send(err)
}
})
})
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(5000);
console.log('App is listening on port 5000');
有什么办法吗?
【问题讨论】:
标签: reactjs express amazon-s3 cors