forked from cloudflare/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch to hard tabs for indentation (cloudflare#76)
* refactor: switch to hard tabs for indentation * chore: update to latest prettier
- Loading branch information
Showing
115 changed files
with
17,627 additions
and
17,627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
{ | ||
"semi": true, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"insertPragma": false, | ||
"requirePragma": false, | ||
"jsxSingleQuote": false, | ||
"bracketSameLine": false, | ||
"embeddedLanguageFormatting": "auto", | ||
"htmlWhitespaceSensitivity": "css", | ||
"vueIndentScriptAndStyle": true, | ||
"quoteProps": "consistent", | ||
"proseWrap": "preserve", | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"useTabs": false, | ||
"tabWidth": 2 | ||
"semi": true, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"insertPragma": false, | ||
"requirePragma": false, | ||
"jsxSingleQuote": false, | ||
"bracketSameLine": false, | ||
"embeddedLanguageFormatting": "auto", | ||
"htmlWhitespaceSensitivity": "css", | ||
"vueIndentScriptAndStyle": true, | ||
"quoteProps": "consistent", | ||
"proseWrap": "preserve", | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"useTabs": true, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
// Serve different variants of your site to different visitors | ||
|
||
export default { | ||
/** | ||
* @param {Request} request | ||
* @returns {Promise<Response>} | ||
*/ | ||
async fetch(request) { | ||
const name = 'experiment-0'; | ||
let group; // 'control' or 'test', set below | ||
let isNew = false; // is the group newly-assigned? | ||
/** | ||
* @param {Request} request | ||
* @returns {Promise<Response>} | ||
*/ | ||
async fetch(request) { | ||
const name = 'experiment-0'; | ||
let group; // 'control' or 'test', set below | ||
let isNew = false; // is the group newly-assigned? | ||
|
||
// Determine which group this request is in. | ||
const cookie = request.headers.get('Cookie'); | ||
if (cookie && cookie.includes(`${name}=control`)) { | ||
group = 'control'; | ||
} else if (cookie && cookie.includes(`${name}=test`)) { | ||
group = 'test'; | ||
} else { | ||
// 50/50 Split | ||
group = Math.random() < 0.5 ? 'control' : 'test'; | ||
isNew = true; | ||
} | ||
// Determine which group this request is in. | ||
const cookie = request.headers.get('Cookie'); | ||
if (cookie && cookie.includes(`${name}=control`)) { | ||
group = 'control'; | ||
} else if (cookie && cookie.includes(`${name}=test`)) { | ||
group = 'test'; | ||
} else { | ||
// 50/50 Split | ||
group = Math.random() < 0.5 ? 'control' : 'test'; | ||
isNew = true; | ||
} | ||
|
||
// We'll prefix the request path with the experiment name. This way, | ||
// the origin server merely has to have two copies of the site under | ||
// top-level directories named "control" and "test". | ||
let url = new URL(request.url); | ||
url.pathname = `/${group}${url.pathname}`; | ||
// We'll prefix the request path with the experiment name. This way, | ||
// the origin server merely has to have two copies of the site under | ||
// top-level directories named "control" and "test". | ||
let url = new URL(request.url); | ||
url.pathname = `/${group}${url.pathname}`; | ||
|
||
// dispatch the modified request | ||
const response = await fetch(url, { | ||
method: request.method, | ||
headers: request.headers, | ||
}); | ||
// dispatch the modified request | ||
const response = await fetch(url, { | ||
method: request.method, | ||
headers: request.headers, | ||
}); | ||
|
||
if (isNew) { | ||
// The experiment was newly-assigned, so add | ||
// a Set-Cookie header to the response. | ||
const newHeaders = new Headers(response.headers); | ||
newHeaders.append('Set-Cookie', `${name}=${group}`); | ||
return new Response(response.body, { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: newHeaders, | ||
}); | ||
} else { | ||
// Return response unmodified. | ||
return response; | ||
} | ||
}, | ||
if (isNew) { | ||
// The experiment was newly-assigned, so add | ||
// a Set-Cookie header to the response. | ||
const newHeaders = new Headers(response.headers); | ||
newHeaders.append('Set-Cookie', `${name}=${group}`); | ||
return new Response(response.body, { | ||
status: response.status, | ||
statusText: response.statusText, | ||
headers: newHeaders, | ||
}); | ||
} else { | ||
// Return response unmodified. | ||
return response; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
// Make multiple requests, aggregate the responses | ||
// and send them back as a single response. | ||
export default { | ||
/** | ||
* @returns {Promise<Response>} | ||
*/ | ||
async fetch() { | ||
const init = { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': 'XXXXXX', | ||
'Content-Type': 'text/plain', | ||
}, | ||
}; | ||
/** | ||
* @returns {Promise<Response>} | ||
*/ | ||
async fetch() { | ||
const init = { | ||
method: 'GET', | ||
headers: { | ||
'Authorization': 'XXXXXX', | ||
'Content-Type': 'text/plain', | ||
}, | ||
}; | ||
|
||
const [btcResp, ethResp, ltcResp] = await Promise.all([ | ||
fetch('https://api.coinbase.com/v2/prices/BTC-USD/spot', init), | ||
fetch('https://api.coinbase.com/v2/prices/ETH-USD/spot', init), | ||
fetch('https://api.coinbase.com/v2/prices/LTC-USD/spot', init), | ||
]); | ||
const [btcResp, ethResp, ltcResp] = await Promise.all([ | ||
fetch('https://api.coinbase.com/v2/prices/BTC-USD/spot', init), | ||
fetch('https://api.coinbase.com/v2/prices/ETH-USD/spot', init), | ||
fetch('https://api.coinbase.com/v2/prices/LTC-USD/spot', init), | ||
]); | ||
|
||
const [btc, eth, ltc] = await Promise.all([btcResp.json(), ethResp.json(), ltcResp.json()]); | ||
const [btc, eth, ltc] = await Promise.all([btcResp.json(), ethResp.json(), ltcResp.json()]); | ||
|
||
const combined = { | ||
btc: btc['data'].amount, | ||
ltc: ltc['data'].amount, | ||
eth: eth['data'].amount, | ||
}; | ||
const combined = { | ||
btc: btc['data'].amount, | ||
ltc: ltc['data'].amount, | ||
eth: eth['data'].amount, | ||
}; | ||
|
||
return new Response(JSON.stringify(combined), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
return new Response(JSON.stringify(combined), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.