How do i allow a CORS requests in my google script?
up vote
1
down vote
favorite
I want to post my contact form to my google script that will send an e-mail to me. I use the following code:
var TO_ADDRESS = "example@gmail.com"; // where to send form data
function doPost(e) {
var callback = e.parameter.callback;
try {
Logger.log(e); // the Google Script version of console.log
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(callback+
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(callback+JSON.stringify({"result":"error",
"error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
When i try to post to the google script url, i get the following error:
Access to XMLHttpRequest at
'https://script.google.com/macros/s/~~myscriptid~~/exec' from origin
'http://localhost:4200' 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.
I have no clue how to add the CORS-filter to my google script.
I know the script is working i have tested it with this plugin:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
google-apps-script cors
|
show 1 more comment
up vote
1
down vote
favorite
I want to post my contact form to my google script that will send an e-mail to me. I use the following code:
var TO_ADDRESS = "example@gmail.com"; // where to send form data
function doPost(e) {
var callback = e.parameter.callback;
try {
Logger.log(e); // the Google Script version of console.log
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(callback+
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(callback+JSON.stringify({"result":"error",
"error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
When i try to post to the google script url, i get the following error:
Access to XMLHttpRequest at
'https://script.google.com/macros/s/~~myscriptid~~/exec' from origin
'http://localhost:4200' 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.
I have no clue how to add the CORS-filter to my google script.
I know the script is working i have tested it with this plugin:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
google-apps-script cors
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
according to error message your script running atlocalhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?
– skyboyer
Nov 22 at 15:31
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
1
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to post my contact form to my google script that will send an e-mail to me. I use the following code:
var TO_ADDRESS = "example@gmail.com"; // where to send form data
function doPost(e) {
var callback = e.parameter.callback;
try {
Logger.log(e); // the Google Script version of console.log
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(callback+
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(callback+JSON.stringify({"result":"error",
"error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
When i try to post to the google script url, i get the following error:
Access to XMLHttpRequest at
'https://script.google.com/macros/s/~~myscriptid~~/exec' from origin
'http://localhost:4200' 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.
I have no clue how to add the CORS-filter to my google script.
I know the script is working i have tested it with this plugin:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
google-apps-script cors
I want to post my contact form to my google script that will send an e-mail to me. I use the following code:
var TO_ADDRESS = "example@gmail.com"; // where to send form data
function doPost(e) {
var callback = e.parameter.callback;
try {
Logger.log(e); // the Google Script version of console.log
MailApp.sendEmail(TO_ADDRESS, "Contact Form Submitted",
JSON.stringify(e.parameters));
// return json success results
return ContentService
.createTextOutput(callback+
JSON.stringify({"result":"success",
"data": JSON.stringify(e.parameters) }))
.setMimeType(ContentService.MimeType.JSON);
} catch(error) { // if error return this
Logger.log(error);
return ContentService
.createTextOutput(callback+JSON.stringify({"result":"error",
"error": e}))
.setMimeType(ContentService.MimeType.JSON);
}
}
When i try to post to the google script url, i get the following error:
Access to XMLHttpRequest at
'https://script.google.com/macros/s/~~myscriptid~~/exec' from origin
'http://localhost:4200' 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.
I have no clue how to add the CORS-filter to my google script.
I know the script is working i have tested it with this plugin:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
google-apps-script cors
google-apps-script cors
asked Nov 22 at 15:17
Joost Kaal
424
424
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
according to error message your script running atlocalhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?
– skyboyer
Nov 22 at 15:31
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
1
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07
|
show 1 more comment
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
according to error message your script running atlocalhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?
– skyboyer
Nov 22 at 15:31
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
1
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
according to error message your script running at
localhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?– skyboyer
Nov 22 at 15:31
according to error message your script running at
localhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?– skyboyer
Nov 22 at 15:31
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
1
1
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
As far as I understood you have application to be run on custom domain. And it should access script on google cloud.
The bad news: there are no way to skip CORS check on your application side(until request is simple that I believe is not your case).
You should specify Access-Control-Allow-Origin
on Google Cloud side:
Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.
You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:
storage.googleapis.com/[BUCKET_NAME]
[BUCKET_NAME].storage.googleapis.com
If this does not help for any reason you will need to get your own server working as a proxy:
your client application <-> your backend that returns Access-Control-Allow-Origin
<-> google cloud
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
As far as I understood you have application to be run on custom domain. And it should access script on google cloud.
The bad news: there are no way to skip CORS check on your application side(until request is simple that I believe is not your case).
You should specify Access-Control-Allow-Origin
on Google Cloud side:
Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.
You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:
storage.googleapis.com/[BUCKET_NAME]
[BUCKET_NAME].storage.googleapis.com
If this does not help for any reason you will need to get your own server working as a proxy:
your client application <-> your backend that returns Access-Control-Allow-Origin
<-> google cloud
add a comment |
up vote
0
down vote
accepted
As far as I understood you have application to be run on custom domain. And it should access script on google cloud.
The bad news: there are no way to skip CORS check on your application side(until request is simple that I believe is not your case).
You should specify Access-Control-Allow-Origin
on Google Cloud side:
Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.
You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:
storage.googleapis.com/[BUCKET_NAME]
[BUCKET_NAME].storage.googleapis.com
If this does not help for any reason you will need to get your own server working as a proxy:
your client application <-> your backend that returns Access-Control-Allow-Origin
<-> google cloud
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
As far as I understood you have application to be run on custom domain. And it should access script on google cloud.
The bad news: there are no way to skip CORS check on your application side(until request is simple that I believe is not your case).
You should specify Access-Control-Allow-Origin
on Google Cloud side:
Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.
You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:
storage.googleapis.com/[BUCKET_NAME]
[BUCKET_NAME].storage.googleapis.com
If this does not help for any reason you will need to get your own server working as a proxy:
your client application <-> your backend that returns Access-Control-Allow-Origin
<-> google cloud
As far as I understood you have application to be run on custom domain. And it should access script on google cloud.
The bad news: there are no way to skip CORS check on your application side(until request is simple that I believe is not your case).
You should specify Access-Control-Allow-Origin
on Google Cloud side:
Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.
You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:
storage.googleapis.com/[BUCKET_NAME]
[BUCKET_NAME].storage.googleapis.com
If this does not help for any reason you will need to get your own server working as a proxy:
your client application <-> your backend that returns Access-Control-Allow-Origin
<-> google cloud
answered Nov 23 at 9:09
skyboyer
3,14111128
3,14111128
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53433938%2fhow-do-i-allow-a-cors-requests-in-my-google-script%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
where is your script expecting to be run? I believe currently you run it from localhost for development purposes. but how do you plan use it in the future?
– skyboyer
Nov 22 at 15:23
The script runs in the google cloud, my application runs on localhost. It is a school assignment.
– Joost Kaal
Nov 22 at 15:25
according to error message your script running at
localhost
is trying to access google cloud. But you say script should be run on google cloud. Am I missing something?– skyboyer
Nov 22 at 15:31
The script runs on google cloud, and gets called by my angular application.
– Joost Kaal
Nov 22 at 15:35
1
sou CORS affects your angular application. where will it be run finally? there are different solutions possible depending on if it will run also at cloud,
– skyboyer
Nov 22 at 16:07