How allow my app to POST a cloudfunction in firebase that makes another POST?
I'm trying a react app that consumes firebase functions, here my code:
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
Then, my index.js function
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
When i run it, console shows this error:
Failed to load https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://bora-ajudar-73ebc.firebaseapp.com' is therefore not allowed access. The response had HTTP status code 500.
I know that is something about sending POST to my function and my function sending another POST, but i dont know exactly what.
node.js firebase google-cloud-functions
add a comment |
I'm trying a react app that consumes firebase functions, here my code:
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
Then, my index.js function
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
When i run it, console shows this error:
Failed to load https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://bora-ajudar-73ebc.firebaseapp.com' is therefore not allowed access. The response had HTTP status code 500.
I know that is something about sending POST to my function and my function sending another POST, but i dont know exactly what.
node.js firebase google-cloud-functions
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29
add a comment |
I'm trying a react app that consumes firebase functions, here my code:
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
Then, my index.js function
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
When i run it, console shows this error:
Failed to load https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://bora-ajudar-73ebc.firebaseapp.com' is therefore not allowed access. The response had HTTP status code 500.
I know that is something about sending POST to my function and my function sending another POST, but i dont know exactly what.
node.js firebase google-cloud-functions
I'm trying a react app that consumes firebase functions, here my code:
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
Then, my index.js function
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
When i run it, console shows this error:
Failed to load https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://bora-ajudar-73ebc.firebaseapp.com' is therefore not allowed access. The response had HTTP status code 500.
I know that is something about sending POST to my function and my function sending another POST, but i dont know exactly what.
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
handleDonate(key)
const url = 'https://us-central1-bora-ajudar-73ebc.cloudfunctions.net/api/donate'
const dados = teste : 'oi'
const options =
method: 'POST',
headers: 'Access-Control-Allow-Origin' : '*',
data : dados,
url
axios(options)
.then(data=>
console.log(data)
)
.catch(err =>
console.log(err)
)
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
app.use(cors(origin: true));
admin.initializeApp()
const checkoutUrl = 'https://pagseguro.uol.com.br/v2/checkout/payment.html?code='
app.use(bodyParser.json())
app.use(bodyParser.urlencoded(extended:true))
app.get('/api', (req,res)=>
res.send('Server side')
)
app.post('/donate',(req,res)=>
request(
uri: 'https://ws.pagseguro.uol.com.br/v2/checkout?',
method: 'POST',
form:
token: token,
email: email,
currency: 'BRL',
itemId1: 'idCampanha',
itemDescription1: 'Doação',
itemQuantity1: '1',
itemAmount1: '2.00'
,
headers:
'Content-Type': 'application/x-www-urlencode; charset=UTF8',
'Access-Control-Allow-Origin': 'true'
)
.then(data=>
parse(data, (err,json)=>
res.setHeader('Access-Control-Allow-Origin', 'true')
res.send(
url: checkoutUrl+json.checkout.code[0]
)
)
)
)
node.js firebase google-cloud-functions
node.js firebase google-cloud-functions
edited Nov 14 '18 at 15:29
Matheus Souza
asked Nov 13 '18 at 15:04
Matheus SouzaMatheus Souza
205
205
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29
add a comment |
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29
add a comment |
1 Answer
1
active
oldest
votes
The problem is that firebase don't allow external API requests in free plan.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283884%2fhow-allow-my-app-to-post-a-cloudfunction-in-firebase-that-makes-another-post%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is that firebase don't allow external API requests in free plan.
add a comment |
The problem is that firebase don't allow external API requests in free plan.
add a comment |
The problem is that firebase don't allow external API requests in free plan.
The problem is that firebase don't allow external API requests in free plan.
answered Nov 21 '18 at 11:49
Matheus SouzaMatheus Souza
205
205
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283884%2fhow-allow-my-app-to-post-a-cloudfunction-in-firebase-that-makes-another-post%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The 500 status of the response is the problem you need to solve. The cause has nothing at all to do with CORS. That console message is just telling you that it can’t expose the response to your frontend code because it doesn’t have the Access-Control-Allow-Origin header.
– sideshowbarker
Nov 13 '18 at 22:54
Thanks for advise. Tried setting the header, but it dont worked :/
– Matheus Souza
Nov 14 '18 at 15:29