-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07a8d00
commit ff35a6c
Showing
5 changed files
with
71 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import createFetchForOrigin from '../../utils/createFetchForOrigin'; | ||
import '../../utils/polyfills/URL'; | ||
|
||
const fetch = createFetchForOrigin('echo'); | ||
|
||
export async function handleHttpRequest(request, context) { | ||
const { method } = request; | ||
const body = method === 'POST' ? await request.arrayBuffer() : null; | ||
|
||
// get the headers from the incoming request, removing the content-length header | ||
const headers = Object.fromEntries( | ||
[...request.headers.entries()].filter(([key]) => key !== 'content-length') | ||
); | ||
|
||
const newRequest = new Request('https://http-echo.raees.me', { | ||
method, | ||
headers, | ||
body, | ||
}); | ||
|
||
const response = await fetch(newRequest); | ||
|
||
// add a cache-control header for GET requests | ||
if (method === 'GET') { | ||
response.headers.set('cache-control', 's-maxage=600'); | ||
} | ||
|
||
return response; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -18,10 +18,10 @@ | |
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@edgio/cli": "^7.2.7", | ||
"@edgio/core": "^7.2.7", | ||
"@edgio/devtools": "^7.2.7", | ||
"@edgio/prefetch": "^7.2.7", | ||
"@edgio/cli": "^7.2.8", | ||
"@edgio/core": "^7.2.8", | ||
"@edgio/devtools": "^7.2.8", | ||
"@edgio/prefetch": "^7.2.8", | ||
"dotenv": "^16.3.1" | ||
}, | ||
"repository": "[email protected]:edgio-docs/edgio-v7-edge-functions-example.git", | ||
|
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