CORS error tryouts.

This commit is contained in:
Naida Vatric
2020-02-18 23:49:00 +01:00
parent c11248e100
commit b13b4bc7c2
3 changed files with 20 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ const {
const app = express();
app.use(cors());
app.use(forceSSL());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
@@ -36,8 +38,6 @@ app.use("/", routes);
app.use("/assets", express.static("./app/public"));
app.use(cors());
app.listen(APP_PORT, () =>
console.log(`Example app listening on port ${APP_PORT}!`)
);
@@ -77,7 +77,8 @@ app.get("/generateSignedURL", (req, res) => {
//Tried to define Google ID and private key while debugging
version: "v2", //tried v4 also
action: "write",
contentType: "image/*", //tried without and with specific image/png ex.
"Content-Type": "image/*",
//contentType: "image/*", //tried without and with specific image/png ex.
expires: Date.now() + 86400000
};
const filename = req.query.filename;
@@ -88,7 +89,12 @@ app.get("/generateSignedURL", (req, res) => {
const [url] = await bucket.file(filename).getSignedUrl(options);
console.log(`The signed url is ${url}.`);
res.send(url);
res.header("Access-Control-Allow-Origin", "http://localhost:5000");
res.header("Access-Control-Allow-Methods", "PUT,OPTIONS");
res.header("Access-Control-Allow-Headers", "Content-Type, Origin");
res.header("Access-Control-Max-Age", "86400000");
res.status(200).send(url);
}
generateSignedUrl().catch(console.error);
});