Skip to content

Commit

Permalink
Override request URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pyropy committed Dec 10, 2024
1 parent 05d725f commit 6ad9d3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ async function reportMetric(request, response, startTime, endTime, env) {

export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
const newUrl = `${env.REQUEST_URL}${url.pathname}${url.search}`;
// override the request with the new URL
request = new Request(newUrl, request);
const reqStartTime = Date.now();
const response = await fetch('https://example.com');
const response = await fetch(request);
const reqEndTime = Date.now();

ctx.waitUntil(reportMetric(request, response, reqStartTime, reqEndTime, env));
return response;
}
Expand Down
1 change: 1 addition & 0 deletions wrangler.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ compatibility_date = "2024-12-05"
compatibility_flags = ["nodejs_compat"]

[vars]
REQUEST_URL = "https://example.com"
INFLUX_METRIC = "example"
INFLUX_URL = "http://localhost:8086"
INFLUX_TOKEN = "example"
Expand Down

0 comments on commit 6ad9d3a

Please sign in to comment.