I have an express server, which works locally, but when I deploy it to App Engine and send a request I get the response that it has been blocked by CORS policy. If I remove the section where I call exec (and move send response) there is no error.
Why could this be happening?
My code:
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const { exec } = require('child_process');
const app = express();
app.use(bodyParser.json());
app.use(cors());
module.exports = app
app.post("/", (req,res) =>{
console.log("Get from /");
console.log(req.body.data)
//IF I COMMENT EXEC OUT IT WORKS
exec('npx hardhat run scripts/deploy.js --network goerli',
(error, stdout, stderr) => {
if (error !== null) {
console.log(`exec error: ${error}`);
}
else{
res.send("response");
}
})
});
app.listen(8080, () => {
console.log('listening on port 8080');
});
This is my package.json:
{
"name": "hardhat-project",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.6",
"ethers": "^5.6.9",
"hardhat": "^2.9.9"
},
"version": "1.0.0",
"description": "smart contract",
"main": "hardhat.config.js",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.1",
"firebase-admin": "^11.0.0"
},
"scripts": {
"start": "node src/index.js",
"test": "mocha"
},
"author": "",
"license": "ISC"
}