Skip to content

Commit

Permalink
Fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri committed Aug 30, 2018
1 parent c7d9ba9 commit f09d23f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ exports.getSignedUrl = (req, res) => {
*/
exports.corsEnabledFunction = (req, res) => {
// Set CORS headers for preflight requests
// e.g. allow GETs from any origin with the Content-Type header
// and cache preflight response for an 3600s
// Allows GETs from any origin with the Content-Type header
// and caches preflight response for 3600s

res.set('Access-Control-Allow-Origin', '*');

// Send response to OPTIONS requests and terminate the function execution
if (req.method === 'OPTIONS') {
res.set('Access-Control-Allow-Origin', '*');
// Send response to OPTIONS requests
res.set('Access-Control-Allow-Methods', 'GET');
res.set('Access-Control-Allow-Headers', 'Content-Type');
res.set('Access-Control-Max-Age', '3600');
res.status(204).send('');
} else {
// Set CORS headers for the main request
res.set('Access-Control-Allow-Origin', '*');
res.send('Hello World!');
}

// Set CORS headers for the main request
res.set('Access-Control-Allow-Origin', '*');

res.send('Hello World!');
};
// [END functions_http_cors]

Expand All @@ -269,21 +269,19 @@ exports.corsEnabledFunction = (req, res) => {
*/
exports.corsEnabledFunctionAuth = (req, res) => {
// Set CORS headers for preflight requests
// allows GETS from origin https://mydomain.com with Authorization header
// Allows GETs from origin https://mydomain.com with Authorization header

res.set('Access-Control-Allow-Origin', 'https://mydomain.com');
res.set('Access-Control-Allow-Credentials', 'true');

// Send response to OPTIONS requests and terminate the function execution
if (req.method === 'OPTIONS') {
res.set('Access-Control-Allow-Origin', 'https://mydomain.com');
// Send response to OPTIONS requests
res.set('Access-Control-Allow-Methods', 'GET');
res.set('Access-Control-Allow-Headers', 'Authorization');
res.set('Access-Control-Allow-Credentials', 'true');
res.set('Access-Control-Max-Age', '3600');
res.status(204).send('');
} else {
res.send('Hello World!');
}

res.set('Access-Control-Allow-Origin', 'https://mydomain.com');
res.set('Access-Control-Allow-Credentials', 'true');

res.send('Hello World!');
};
// [END functions_http_cors_auth]
2 changes: 1 addition & 1 deletion functions/http/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ test.serial(`http:cors: should respond to preflight request (auth)`, (t) => {
httpSample.sample.corsEnabledFunctionAuth(mocks.corsPreflightReq, mocks.res);

t.true(mocks.res.status.calledOnceWith(204));
t.true(mocks.res.send.calledTwice);
t.true(mocks.res.send.calledOnce);
});

test.serial(`http:cors: should respond to main request (auth)`, (t) => {
Expand Down

0 comments on commit f09d23f

Please sign in to comment.